<?php
/**
 * 为各渠道补齐三个默认代理角色，并清理多余角色（无用户绑定的）
 * 用法: php db/sync_channel_default_roles.php
 */
declare(strict_types=1);

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../support/bootstrap.php';

use plugin\saiadmin\app\service\SystemRoleChannelService;

$service = new SystemRoleChannelService();
echo 'Default role codes: ' . implode(', ', $service->getDefaultChannelRoleCodes()) . "\n";

$sync = $service->syncAllChannelsFromDefault();
echo json_encode($sync, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n";

$mapped = $service->remapUserRolesToChannelRoles();
echo "Remapped user roles: {$mapped}\n";
echo "Done.\n";
