<?php

namespace App\Console\Commands;

use App\Apps\CmsproChildrehab\StaffMigration;
use Illuminate\Console\Command;

/**
 * 儿康系统 Staff 数据迁移命令
 *
 * 将 Staff 表数据迁移到系统用户体系（AdminUser + 角色关联 + 扩展数据）
 */
class MigrateChildrehabStaff extends Command
{
    protected $signature = 'childrehab:migrate-staff';
    protected $description = '迁移儿康系统Staff数据到系统用户体系（AdminUser+角色+扩展字段）';

    public function handle(): int
    {
        $this->info('开始迁移儿康系统Staff数据...');

        $migration = new StaffMigration();
        $result = $migration->migrate();

        $this->info("总计: {$result['total']} 条");
        $this->info("成功: {$result['success']} 条");

        if ($result['skipped'] > 0) {
            $this->warn("跳过: {$result['skipped']} 条");
        }

        if (!empty($result['errors'])) {
            $this->error('错误详情:');
            foreach ($result['errors'] as $error) {
                $this->error("  - {$error}");
            }
            return self::FAILURE;
        }

        $this->info('迁移完成！');
        return self::SUCCESS;
    }
}
