<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents;

    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // Create Admin User
        \Illuminate\Support\Facades\DB::table('users')->insert([
            'name' => 'Admin User',
            'email' => 'admin@example.com',
            'password' => \Illuminate\Support\Facades\Hash::make('password'),
            'role' => 'admin',
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        // Call Seeders
        $this->call([
            WorkerCategorySeeder::class,
            SkillSeeder::class,
            EmployerProfileSeeder::class,
            WorkerSeeder::class,
            JobPostSeeder::class,
        ]);

        // Seed Conversations & Messages (assuming IDs exist)
        $conversationId = \Illuminate\Support\Facades\DB::table('conversations')->insertGetId([
            'employer_id' => 2, // From EmployerProfileSeeder
            'worker_id' => 1, // From WorkerSeeder
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        \Illuminate\Support\Facades\DB::table('messages')->insert([
            [
                'conversation_id' => $conversationId,
                'sender_type' => 'employer',
                'sender_id' => 2,
                'text' => 'Hello, are you available for an interview?',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'conversation_id' => $conversationId,
                'sender_type' => 'worker',
                'sender_id' => 1,
                'text' => 'Yes, I am available.',
                'created_at' => now()->addMinutes(5),
                'updated_at' => now()->addMinutes(5),
            ]
        ]);

        // Seed Subscriptions
        \Illuminate\Support\Facades\DB::table('subscriptions')->insert([
            'user_id' => 2, // Employer created in EmployerProfileSeeder
            'plan_id' => 'premium',
            'amount_aed' => 499.00,
            'starts_at' => now(),
            'expires_at' => now()->addMonth(),
            'status' => 'active',
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        // Seed Payments
        \Illuminate\Support\Facades\DB::table('payments')->insert([
            'user_id' => 2, // Employer
            'amount' => 499.00,
            'currency' => 'AED',
            'description' => 'Premium Monthly Subscription',
            'status' => 'success',
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        // Seed Sponsors (UAE Sponsor Marketplace Portal)
        \Illuminate\Support\Facades\DB::table('sponsors')->insert([
            [
                'full_name' => 'Ahmed Malik (Al Barari Real Estate)',
                'email' => 'hr@albarari.ae',
                'mobile' => '+971 50 123 4567',
                'password' => \Illuminate\Support\Facades\Hash::make('password'),
                'country_code' => 'AE',
                'subscription_status' => 'active',
                'subscription_plan' => 'premium',
                'subscription_start_date' => now()->subDays(15),
                'subscription_end_date' => now()->addDays(350),
                'payment_status' => 'paid',
                'is_verified' => true,
                'otp_verified_at' => now()->subDays(15),
                'profile_image' => null,
                'address' => 'Villa 14, Al Barari',
                'city' => 'Dubai',
                'nationality' => 'Emirati',
                'status' => 'active',
                'last_login_at' => now(),
                'created_at' => now()->subDays(15),
                'updated_at' => now(),
            ],
            [
                'full_name' => 'Sarah Johnson (Marina Cleaners)',
                'email' => 'contact@marinaclean.com',
                'mobile' => '+971 50 234 5678',
                'password' => \Illuminate\Support\Facades\Hash::make('password'),
                'country_code' => 'AE',
                'subscription_status' => 'active',
                'subscription_plan' => 'basic',
                'subscription_start_date' => now()->subDays(10),
                'subscription_end_date' => now()->addDays(355),
                'payment_status' => 'paid',
                'is_verified' => true,
                'otp_verified_at' => now()->subDays(10),
                'profile_image' => null,
                'address' => 'Marina Heights, Floor 22',
                'city' => 'Abu Dhabi',
                'nationality' => 'British',
                'status' => 'active',
                'last_login_at' => now()->subHours(4),
                'created_at' => now()->subDays(10),
                'updated_at' => now(),
            ],
            [
                'full_name' => 'John Doe (Golden Hospitality)',
                'email' => 'hiring@golden.hotel',
                'mobile' => '+971 50 345 6789',
                'password' => \Illuminate\Support\Facades\Hash::make('password'),
                'country_code' => 'AE',
                'subscription_status' => 'none',
                'subscription_plan' => null,
                'subscription_start_date' => null,
                'subscription_end_date' => null,
                'payment_status' => 'unpaid',
                'is_verified' => false,
                'otp_verified_at' => null,
                'profile_image' => null,
                'address' => 'Al Majaz 3, Corniche St',
                'city' => 'Sharjah',
                'nationality' => 'American',
                'status' => 'inactive',
                'last_login_at' => null,
                'created_at' => now()->subDays(2),
                'updated_at' => now(),
            ],
            [
                'full_name' => 'Mike Ross (Emirates Logistics)',
                'email' => 'jobs@emirateslogistics.com',
                'mobile' => '+971 50 456 7890',
                'password' => \Illuminate\Support\Facades\Hash::make('password'),
                'country_code' => 'AE',
                'subscription_status' => 'active',
                'subscription_plan' => 'premium',
                'subscription_start_date' => now()->subDays(30),
                'subscription_end_date' => now()->addDays(335),
                'payment_status' => 'paid',
                'is_verified' => true,
                'otp_verified_at' => now()->subDays(30),
                'profile_image' => null,
                'address' => 'Logistics City, Zone 4',
                'city' => 'Dubai',
                'nationality' => 'Canadian',
                'status' => 'active',
                'last_login_at' => now()->subDays(1),
                'created_at' => now()->subDays(30),
                'updated_at' => now(),
            ],
            [
                'full_name' => 'Jane Foster (Dubai Mall Services)',
                'email' => 'support@dubaimall.ae',
                'mobile' => '+971 50 567 8901',
                'password' => \Illuminate\Support\Facades\Hash::make('password'),
                'country_code' => 'AE',
                'subscription_status' => 'expired',
                'subscription_plan' => 'vip',
                'subscription_start_date' => now()->subDays(400),
                'subscription_end_date' => now()->subDays(35),
                'payment_status' => 'paid',
                'is_verified' => true,
                'otp_verified_at' => now()->subDays(400),
                'profile_image' => null,
                'address' => 'Downtown Dubai Mall Management',
                'city' => 'Dubai',
                'nationality' => 'Australian',
                'status' => 'suspended',
                'last_login_at' => now()->subDays(40),
                'created_at' => now()->subDays(400),
                'updated_at' => now(),
            ]
        ]);

        // Seed Announcements
        \Illuminate\Support\Facades\DB::table('announcements')->insert([
            [
                'title' => 'New Visa Regulations Update',
                'body' => 'The Ministry of Human Resources and Emiratisation has announced updated guidelines for domestic worker sponsorship starting this month.',
                'type' => 'info',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'title' => 'Enhanced OCR Verification Active',
                'body' => 'We have deployed upgraded OCR passport verification to ensure 100% legal compliance for all worker profiles on the platform.',
                'type' => 'info',
                'created_at' => now()->subDays(5),
                'updated_at' => now()->subDays(5),
            ],
        ]);
    }
}
