<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Shared\Models\Members\User;
use Shared\Models\Sales\DemoLink;
use Shared\Models\Sales\Prospect;

class DemoSystemSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // 1. Ops 계정 생성
        $ops = User::create([
            'user_id' => 'OPS001',
            'name' => 'Ops Admin',
            'email' => 'ops@sam.kr',
            'password' => Hash::make('password'),
            'role' => 'ops',
            'is_active' => true,
        ]);

        echo "✅ Ops 계정 생성: ops@sam.kr / password\n";

        // 2. Sales 계정 생성
        $sales = User::create([
            'user_id' => 'SALES001',
            'name' => 'Sales User',
            'email' => 'sales@sam.kr',
            'password' => Hash::make('password'),
            'role' => 'sales',
            'is_active' => true,
        ]);

        echo "✅ Sales 계정 생성: sales@sam.kr / password\n";

        // 3. 샘플 업체 생성
        $prospect = Prospect::create([
            'sales_user_id' => $sales->id,
            'company_name' => '테스트 고객사',
            'contact_person' => '홍길동',
            'email' => 'test@example.com',
            'phone' => '010-1234-5678',
            'notes' => 'MVP 테스트용 샘플 업체입니다.',
        ]);

        echo "✅ 샘플 업체 생성: {$prospect->company_name}\n";

        // 4. 샘플 데모 링크 생성 (3일 만료)
        $demoLink = DemoLink::create([
            'prospect_id' => $prospect->id,
            'created_by' => $sales->id,
            'token' => DemoLink::generateToken(),
            'status' => 'active',
            'expires_at' => now()->addDays(3),
            'visit_count' => 0,
        ]);

        echo "✅ 샘플 데모 링크 생성: http://dev.sam.kr/d/{$demoLink->token}\n";
        echo "\n";
        echo "🎉 데모 시스템 시더 완료!\n";
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
        echo "Ops 로그인: ops@sam.kr / password\n";
        echo "Sales 로그인: sales@sam.kr / password\n";
        echo "데모 링크: http://dev.sam.kr/d/{$demoLink->token}\n";
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    }
}
