<?php

namespace Kylin\Fitness\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

/**
 * 健身系统安装命令
 *
 * Artisan 命令：php artisan kylin:fitness-install
 * 安装健身系统数据库迁移和初始数据。
 */
class FitnessInstallCommand extends Command
{
    protected $signature = 'kylin:fitness-install
        {--force : 强制重新安装}
        {--skip-migration : 跳过数据库迁移}';

    protected $description = '安装智慧健身会所系统模块';

    public function handle(): int
    {
        $this->info('');
        $this->info('  ╔══════════════════════════════════════╗');
        $this->info('  ║   智慧健身会所系统 - 模块安装       ║');
        $this->info('  ╚══════════════════════════════════════╝');
        $this->info('');

        // 发布配置
        $this->info('📦 发布配置文件...');
        Artisan::call('vendor:publish', [
            '--tag' => 'kylin-fitness-config',
            '--force' => $this->option('force'),
        ]);

        // 数据库迁移
        if (!$this->option('skip-migration')) {
            $this->info('🗄️  运行数据库迁移...');
            Artisan::call('migrate', [
                '--force' => true,
                '--graceful' => true,
            ], $this->getOutput());
        }

        $this->info('');
        $this->info('  ✅ 智慧健身会所系统模块安装完成！');
        $this->info('');

        return self::SUCCESS;
    }
}
