<?php

namespace Kylin\LawCase\Commands;

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

/**
 * 律所系统安装命令
 *
 * 执行数据库迁移、配置发布等初始化操作。
 */
class LawCaseInstallCommand extends Command
{
    protected $signature = 'kylin:law-case-install {--force : 强制重新安装}';

    protected $description = '安装智慧律所案件系统模块';

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

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

        // 发布迁移
        $this->info('🗄️  发布迁移文件...');
        Artisan::call('vendor:publish', [
            '--tag' => 'kylin-law-case-migrations',
            '--force' => $this->option('force'),
        ], $this->getOutput());

        // 运行迁移
        $this->info('📊 运行数据库迁移...');
        Artisan::call('migrate', ['--force' => true], $this->getOutput());

        $this->info('');
        $this->info('  ✅ 智慧律所案件系统安装完成！');
        $this->info('');

        return self::SUCCESS;
    }
}
