<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class AllTablesSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $now = now();

        DB::statement('SET FOREIGN_KEY_CHECKS=0;');

        $tablesToTruncate = [
            'role_has_permissions',
            'model_has_roles',
            'model_has_permissions',
            'wallet_transactions',
            'subscription_members',
            'payout_requests',
            'messages',
            'referrals',
            'trust_scores',
            'shared_subscriptions',
            'service_plans',
            'services',
            'categories',
            'wallets',
            'audit_logs',
            'personal_access_tokens',
            'failed_jobs',
            'password_reset_tokens',
            'permissions',
            'roles',
            'general_settings',
            'users',
        ];

        foreach ($tablesToTruncate as $table) {
            DB::table($table)->truncate();
        }

        DB::statement('SET FOREIGN_KEY_CHECKS=1;');

        $realUsers = [
            ['name' => 'Ayesha Khan', 'email' => 'ayesha.khan@example.com'],
            ['name' => 'Bilal Ahmed', 'email' => 'bilal.ahmed@example.com'],
            ['name' => 'Sara Malik', 'email' => 'sara.malik@example.com'],
            ['name' => 'Hamza Ali', 'email' => 'hamza.ali@example.com'],
            ['name' => 'Noor Fatima', 'email' => 'noor.fatima@example.com'],
        ];

        $users = [];
        foreach ($realUsers as $realUser) {
            $users[] = [
                'name' => $realUser['name'],
                'email' => $realUser['email'],
                'email_verified_at' => $now,
                'password' => Hash::make('12345678'),
                'remember_token' => Str::random(10),
                'status' => 'active',
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('users')->insert($users);

        $roleNames = ['super admin', 'admin', 'owner', 'member', 'support'];
        $roles = [];
        foreach ($roleNames as $name) {
            $roles[] = [
                'name' => $name,
                'guard_name' => 'web',
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('roles')->insert($roles);

        $permissionNames = [
            'manage users',
            'manage services',
            'manage plans',
            'join subscription',
            'request payout',
        ];
        $permissions = [];
        foreach ($permissionNames as $name) {
            $permissions[] = [
                'name' => $name,
                'guard_name' => 'web',
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('permissions')->insert($permissions);

        $rolePermissions = [
            ['permission_id' => 1, 'role_id' => 1],
            ['permission_id' => 2, 'role_id' => 2],
            ['permission_id' => 3, 'role_id' => 3],
            ['permission_id' => 4, 'role_id' => 4],
            ['permission_id' => 5, 'role_id' => 3],
        ];

        $modelRoles = [
            ['role_id' => 3, 'model_type' => 'App\\Models\\User', 'model_id' => 1],
            ['role_id' => 4, 'model_type' => 'App\\Models\\User', 'model_id' => 2],
            ['role_id' => 3, 'model_type' => 'App\\Models\\User', 'model_id' => 3],
            ['role_id' => 4, 'model_type' => 'App\\Models\\User', 'model_id' => 4],
            ['role_id' => 2, 'model_type' => 'App\\Models\\User', 'model_id' => 5],
        ];

        $modelPermissions = [
            ['permission_id' => 3, 'model_type' => 'App\\Models\\User', 'model_id' => 1],
            ['permission_id' => 4, 'model_type' => 'App\\Models\\User', 'model_id' => 2],
            ['permission_id' => 3, 'model_type' => 'App\\Models\\User', 'model_id' => 3],
            ['permission_id' => 4, 'model_type' => 'App\\Models\\User', 'model_id' => 4],
            ['permission_id' => 2, 'model_type' => 'App\\Models\\User', 'model_id' => 5],
        ];
        DB::table('role_has_permissions')->insert($rolePermissions);
        DB::table('model_has_roles')->insert($modelRoles);
        DB::table('model_has_permissions')->insert($modelPermissions);

        $settingsData = [
            ['sitename' => 'Global Dezigns Marketplace', 'logo' => 'assets/img/logo-main.png', 'favicon' => 'assets/img/favicon-main.png'],
            ['sitename' => 'Global Dezigns Seller Hub', 'logo' => 'assets/img/logo-seller.png', 'favicon' => 'assets/img/favicon-seller.png'],
            ['sitename' => 'Global Dezigns Shared Subscriptions', 'logo' => 'assets/img/logo-share.png', 'favicon' => 'assets/img/favicon-share.png'],
            ['sitename' => 'Global Dezigns Business Suite', 'logo' => 'assets/img/logo-business.png', 'favicon' => 'assets/img/favicon-business.png'],
            ['sitename' => 'Global Dezigns Learning Hub', 'logo' => 'assets/img/logo-learning.png', 'favicon' => 'assets/img/favicon-learning.png'],
        ];

        $settings = [];
        foreach ($settingsData as $settingData) {
            $settings[] = array_merge($settingData, [
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('general_settings')->insert($settings);

        $categoryMap = [
            ['name' => 'Streaming', 'icon' => 'icons/streaming.svg'],
            ['name' => 'Music', 'icon' => 'icons/music.svg'],
            ['name' => 'Security', 'icon' => 'icons/security.svg'],
            ['name' => 'Productivity', 'icon' => 'icons/productivity.svg'],
            ['name' => 'Education', 'icon' => 'icons/education.svg'],
        ];
        $categories = [];
        foreach ($categoryMap as $categoryData) {
            $categories[] = [
                'name' => $categoryData['name'],
                'slug' => Str::slug($categoryData['name']),
                'icon' => $categoryData['icon'],
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('categories')->insert($categories);

        $serviceData = [
            ['category_id' => 1, 'name' => 'Netflix', 'description' => 'Premium movie and series streaming shared subscriptions.', 'logo' => 'services/netflix.png'],
            ['category_id' => 2, 'name' => 'Spotify', 'description' => 'Family music plan sharing for multi-user listening.', 'logo' => 'services/spotify.png'],
            ['category_id' => 3, 'name' => 'ExpressVPN', 'description' => 'Secure multi-device VPN access for families and teams.', 'logo' => 'services/expressvpn.png'],
            ['category_id' => 4, 'name' => 'Canva', 'description' => 'Design collaboration plan for teams and creators.', 'logo' => 'services/canva.png'],
            ['category_id' => 5, 'name' => 'Coursera Plus', 'description' => 'Unlimited online courses and certificates under one plan.', 'logo' => 'services/coursera-plus.png'],
        ];

        $services = [];
        foreach ($serviceData as $serviceItem) {
            $services[] = [
                'category_id' => $serviceItem['category_id'],
                'name' => $serviceItem['name'],
                'slug' => Str::slug($serviceItem['name']),
                'description' => $serviceItem['description'],
                'logo' => $serviceItem['logo'],
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('services')->insert($services);

        $planData = [
            ['service_id' => 1, 'name' => 'Premium', 'price' => 22.99, 'max_slots' => 4, 'features' => ['4K + HDR', '4 simultaneous screens']],
            ['service_id' => 2, 'name' => 'Family', 'price' => 16.99, 'max_slots' => 6, 'features' => ['Up to 6 accounts', 'Ad-free listening']],
            ['service_id' => 3, 'name' => '12-Month Plan', 'price' => 12.95, 'max_slots' => 5, 'features' => ['5 devices', 'Global server access']],
            ['service_id' => 4, 'name' => 'Teams', 'price' => 14.99, 'max_slots' => 5, 'features' => ['Brand kit', 'Team collaboration']],
            ['service_id' => 5, 'name' => 'Annual Access', 'price' => 59.00, 'max_slots' => 3, 'features' => ['Unlimited certificates', 'Career pathways']],
        ];

        $plans = [];
        foreach ($planData as $planItem) {
            $plans[] = [
                'service_id' => $planItem['service_id'],
                'name' => $planItem['name'],
                'price' => $planItem['price'],
                'currency' => 'USD',
                'max_slots' => $planItem['max_slots'],
                'features' => json_encode($planItem['features']),
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('service_plans')->insert($plans);

        $subscriptionData = [
            [
                'owner_id' => 1, 'service_id' => 1, 'service_plan_id' => 1, 'title' => 'Netflix Premium Family - 1 Slot Left',
                'total_slots' => 4, 'available_slots' => 1, 'total_price' => 22.99, 'price_per_slot' => 5.75,
                'is_public' => true, 'credentials_shared' => true, 'requires_manual_approval' => true,
                'notes' => 'Profiles are managed individually for privacy.', 'starts_at' => $now->copy()->subDays(5), 'ends_at' => $now->copy()->addDays(25),
            ],
            [
                'owner_id' => 2, 'service_id' => 2, 'service_plan_id' => 2, 'title' => 'Spotify Family Plan - Open Slots',
                'total_slots' => 6, 'available_slots' => 2, 'total_price' => 16.99, 'price_per_slot' => 2.83,
                'is_public' => true, 'credentials_shared' => true, 'requires_manual_approval' => false,
                'notes' => 'Only long-term members preferred.', 'starts_at' => $now->copy()->subDays(10), 'ends_at' => $now->copy()->addDays(20),
            ],
            [
                'owner_id' => 3, 'service_id' => 3, 'service_plan_id' => 3, 'title' => 'ExpressVPN Shared Access',
                'total_slots' => 5, 'available_slots' => 2, 'total_price' => 12.95, 'price_per_slot' => 2.59,
                'is_public' => false, 'credentials_shared' => false, 'requires_manual_approval' => true,
                'notes' => 'Manual verification required before adding devices.', 'starts_at' => $now->copy()->subDays(3), 'ends_at' => $now->copy()->addDays(27),
            ],
            [
                'owner_id' => 4, 'service_id' => 4, 'service_plan_id' => 4, 'title' => 'Canva Teams Workspace',
                'total_slots' => 5, 'available_slots' => 3, 'total_price' => 14.99, 'price_per_slot' => 3.00,
                'is_public' => true, 'credentials_shared' => false, 'requires_manual_approval' => false,
                'notes' => 'Invite sent through Canva team email.', 'starts_at' => $now->copy()->subDays(7), 'ends_at' => $now->copy()->addDays(23),
            ],
            [
                'owner_id' => 5, 'service_id' => 5, 'service_plan_id' => 5, 'title' => 'Coursera Plus Study Group',
                'total_slots' => 3, 'available_slots' => 1, 'total_price' => 59.00, 'price_per_slot' => 19.67,
                'is_public' => true, 'credentials_shared' => true, 'requires_manual_approval' => true,
                'notes' => 'Best for professional certificate learners.', 'starts_at' => $now->copy()->subDays(2), 'ends_at' => $now->copy()->addDays(29),
            ],
        ];

        $sharedSubscriptions = [];
        foreach ($subscriptionData as $subscriptionItem) {
            $sharedSubscriptions[] = array_merge($subscriptionItem, [
                'status' => 'active',
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('shared_subscriptions')->insert($sharedSubscriptions);

        $memberData = [
            ['shared_subscription_id' => 1, 'user_id' => 2, 'subscription_amount' => 5.75, 'platform_fee' => 0.58, 'owner_connection_fee' => 0.25, 'status' => 'active', 'payment_verified' => true, 'joined_at' => $now->copy()->subDays(4), 'expires_at' => $now->copy()->addDays(26)],
            ['shared_subscription_id' => 2, 'user_id' => 3, 'subscription_amount' => 2.83, 'platform_fee' => 0.28, 'owner_connection_fee' => 0.10, 'status' => 'active', 'payment_verified' => true, 'joined_at' => $now->copy()->subDays(8), 'expires_at' => $now->copy()->addDays(22)],
            ['shared_subscription_id' => 3, 'user_id' => 4, 'subscription_amount' => 2.59, 'platform_fee' => 0.26, 'owner_connection_fee' => 0.10, 'status' => 'pending', 'payment_verified' => false, 'joined_at' => $now->copy()->subDay(), 'expires_at' => $now->copy()->addDays(29)],
            ['shared_subscription_id' => 4, 'user_id' => 5, 'subscription_amount' => 3.00, 'platform_fee' => 0.30, 'owner_connection_fee' => 0.10, 'status' => 'active', 'payment_verified' => true, 'joined_at' => $now->copy()->subDays(6), 'expires_at' => $now->copy()->addDays(24)],
            ['shared_subscription_id' => 5, 'user_id' => 1, 'subscription_amount' => 19.67, 'platform_fee' => 1.97, 'owner_connection_fee' => 0.50, 'status' => 'active', 'payment_verified' => true, 'joined_at' => $now->copy()->subDay(), 'expires_at' => $now->copy()->addDays(29)],
        ];

        $members = [];
        foreach ($memberData as $memberItem) {
            $members[] = array_merge($memberItem, [
                'slots_taken' => 1,
                'cancel_requested_at' => null,
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('subscription_members')->insert($members);

        $walletBalances = [146.75, 82.40, 310.10, 54.95, 201.30];
        $wallets = [];
        foreach ($walletBalances as $index => $balance) {
            $wallets[] = [
                'user_id' => $index + 1,
                'balance' => $balance,
                'currency' => 'USD',
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('wallets')->insert($wallets);

        $transactionData = [
            ['wallet_id' => 2, 'user_id' => 2, 'shared_subscription_id' => 1, 'subscription_member_id' => 1, 'type' => 'debit', 'amount' => 5.75, 'status' => 'completed', 'reference' => 'SUBPAY-20260308-001', 'description' => 'Payment for Netflix Premium shared slot.'],
            ['wallet_id' => 3, 'user_id' => 3, 'shared_subscription_id' => 2, 'subscription_member_id' => 2, 'type' => 'debit', 'amount' => 2.83, 'status' => 'completed', 'reference' => 'SUBPAY-20260308-002', 'description' => 'Payment for Spotify Family shared slot.'],
            ['wallet_id' => 4, 'user_id' => 4, 'shared_subscription_id' => 3, 'subscription_member_id' => 3, 'type' => 'debit', 'amount' => 2.59, 'status' => 'pending', 'reference' => 'SUBPAY-20260308-003', 'description' => 'Pending payment for ExpressVPN shared slot.'],
            ['wallet_id' => 5, 'user_id' => 5, 'shared_subscription_id' => 4, 'subscription_member_id' => 4, 'type' => 'debit', 'amount' => 3.00, 'status' => 'completed', 'reference' => 'SUBPAY-20260308-004', 'description' => 'Payment for Canva Teams shared slot.'],
            ['wallet_id' => 1, 'user_id' => 1, 'shared_subscription_id' => 5, 'subscription_member_id' => 5, 'type' => 'debit', 'amount' => 19.67, 'status' => 'completed', 'reference' => 'SUBPAY-20260308-005', 'description' => 'Payment for Coursera Plus annual shared access.'],
        ];

        $transactions = [];
        foreach ($transactionData as $transactionItem) {
            $transactions[] = array_merge($transactionItem, [
                'currency' => 'USD',
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('wallet_transactions')->insert($transactions);

        $payoutData = [
            ['user_id' => 1, 'amount' => 18.25, 'bank_name' => 'HBL', 'account_name' => 'Ayesha Khan', 'account_number' => '0213456789', 'iban' => 'PK36HABB0000002134567890', 'swift_code' => 'HABBPKKA', 'status' => 'pending', 'admin_note' => null, 'processed_at' => null],
            ['user_id' => 2, 'amount' => 12.50, 'bank_name' => 'Meezan Bank', 'account_name' => 'Bilal Ahmed', 'account_number' => '0312345678', 'iban' => 'PK54MEZN0000003123456789', 'swift_code' => 'MEZNPKKA', 'status' => 'approved', 'admin_note' => 'Approved in weekly payout batch.', 'processed_at' => $now->copy()->subDay()],
            ['user_id' => 3, 'amount' => 9.80, 'bank_name' => 'UBL', 'account_name' => 'Sara Malik', 'account_number' => '0412345678', 'iban' => 'PK78UNIL0000004123456789', 'swift_code' => 'UNILPKKA', 'status' => 'pending', 'admin_note' => null, 'processed_at' => null],
            ['user_id' => 4, 'amount' => 6.40, 'bank_name' => 'Allied Bank', 'account_name' => 'Hamza Ali', 'account_number' => '0512345678', 'iban' => 'PK90ABPA0000005123456789', 'swift_code' => 'ABPAPKKA', 'status' => 'rejected', 'admin_note' => 'Bank details could not be verified.', 'processed_at' => $now->copy()->subDays(2)],
            ['user_id' => 5, 'amount' => 24.90, 'bank_name' => 'Bank Alfalah', 'account_name' => 'Noor Fatima', 'account_number' => '0612345678', 'iban' => 'PK12ALFH0000006123456789', 'swift_code' => 'ALFHPKKA', 'status' => 'approved', 'admin_note' => 'Processed successfully.', 'processed_at' => $now->copy()->subDays(3)],
        ];

        $payouts = [];
        foreach ($payoutData as $payoutItem) {
            $payouts[] = array_merge($payoutItem, [
                'currency' => 'USD',
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('payout_requests')->insert($payouts);

        $trustScoreData = [
            ['user_id' => 1, 'reviewed_by' => 5, 'score_change' => 2.00, 'reason' => 'Successful handover', 'notes' => 'Delivered access details on time.'],
            ['user_id' => 2, 'reviewed_by' => 1, 'score_change' => 1.50, 'reason' => 'Consistent payments', 'notes' => 'No missed billing cycles.'],
            ['user_id' => 3, 'reviewed_by' => 2, 'score_change' => -0.50, 'reason' => 'Late response', 'notes' => 'Support message response delayed.'],
            ['user_id' => 4, 'reviewed_by' => 3, 'score_change' => 1.20, 'reason' => 'Quick communication', 'notes' => 'Resolved membership issue fast.'],
            ['user_id' => 5, 'reviewed_by' => 4, 'score_change' => 2.30, 'reason' => 'Verified identity', 'notes' => 'Completed account verification checks.'],
        ];

        $trustScores = [];
        foreach ($trustScoreData as $trustScoreItem) {
            $trustScores[] = array_merge($trustScoreItem, [
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('trust_scores')->insert($trustScores);

        $messageData = [
            ['shared_subscription_id' => 1, 'sender_id' => 1, 'receiver_id' => 2, 'message' => 'Hi Bilal, your Netflix profile is now ready.', 'is_read' => true],
            ['shared_subscription_id' => 2, 'sender_id' => 2, 'receiver_id' => 3, 'message' => 'Sara, Spotify invite link has been sent to your email.', 'is_read' => true],
            ['shared_subscription_id' => 3, 'sender_id' => 3, 'receiver_id' => 4, 'message' => 'Hamza, VPN credentials will be shared after payment verification.', 'is_read' => false],
            ['shared_subscription_id' => 4, 'sender_id' => 4, 'receiver_id' => 5, 'message' => 'Noor, you have been added to the Canva team workspace.', 'is_read' => true],
            ['shared_subscription_id' => 5, 'sender_id' => 5, 'receiver_id' => 1, 'message' => 'Ayesha, Coursera Plus annual access is activated.', 'is_read' => false],
        ];

        $messages = [];
        foreach ($messageData as $messageItem) {
            $messages[] = array_merge($messageItem, [
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('messages')->insert($messages);

        $referralData = [
            ['referrer_id' => 1, 'referred_user_id' => 2, 'code' => 'AKHAN10', 'reward_amount' => 5.00, 'status' => 'completed'],
            ['referrer_id' => 2, 'referred_user_id' => 3, 'code' => 'BILAL15', 'reward_amount' => 7.50, 'status' => 'completed'],
            ['referrer_id' => 3, 'referred_user_id' => 4, 'code' => 'SARA20', 'reward_amount' => 10.00, 'status' => 'pending'],
            ['referrer_id' => 4, 'referred_user_id' => 5, 'code' => 'HAMZA5', 'reward_amount' => 2.50, 'status' => 'completed'],
            ['referrer_id' => 5, 'referred_user_id' => 1, 'code' => 'NOOR12', 'reward_amount' => 6.00, 'status' => 'completed'],
        ];

        $referrals = [];
        foreach ($referralData as $referralItem) {
            $referrals[] = array_merge($referralItem, [
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('referrals')->insert($referrals);

        $auditData = [
            ['table_name' => 'shared_subscriptions', 'record_id' => 1, 'action' => 'created', 'user_id' => 1, 'description' => 'Created Netflix shared listing.', 'changes' => json_encode(['status' => 'active', 'available_slots' => 1])],
            ['table_name' => 'subscription_members', 'record_id' => 2, 'action' => 'updated', 'user_id' => 2, 'description' => 'Member payment marked as verified.', 'changes' => json_encode(['payment_verified' => true])],
            ['table_name' => 'wallet_transactions', 'record_id' => 3, 'action' => 'created', 'user_id' => 4, 'description' => 'Pending debit recorded for ExpressVPN slot.', 'changes' => json_encode(['status' => 'pending', 'amount' => 2.59])],
            ['table_name' => 'payout_requests', 'record_id' => 4, 'action' => 'updated', 'user_id' => 4, 'description' => 'Payout request rejected after verification.', 'changes' => json_encode(['status' => 'rejected'])],
            ['table_name' => 'trust_scores', 'record_id' => 5, 'action' => 'created', 'user_id' => 5, 'description' => 'Trust score increased after verification.', 'changes' => json_encode(['score_change' => 2.30])],
        ];

        $auditLogs = [];
        foreach ($auditData as $auditItem) {
            $auditLogs[] = array_merge($auditItem, [
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
        DB::table('audit_logs')->insert($auditLogs);

        $passwordResetTokens = [];
        foreach (array_column($users, 'email') as $email) {
            $passwordResetTokens[] = [
                'email' => $email,
                'token' => Str::random(60),
                'created_at' => $now,
            ];
        }
        DB::table('password_reset_tokens')->insert($passwordResetTokens);

        $failedJobData = [
            ['payload' => json_encode(['job' => 'SendSubscriptionReminder', 'subscription_id' => 3]), 'exception' => 'Timeout while contacting mail provider.'],
            ['payload' => json_encode(['job' => 'ProcessPayoutBatch', 'batch' => 'weekly-10']), 'exception' => 'Bank API returned invalid account error.'],
            ['payload' => json_encode(['job' => 'SyncTrustScores', 'user_id' => 3]), 'exception' => 'Database deadlock detected while updating trust score.'],
            ['payload' => json_encode(['job' => 'SendReferralReward', 'referral_id' => 4]), 'exception' => 'Wallet service unavailable.'],
            ['payload' => json_encode(['job' => 'ExpireSubscriptionMember', 'member_id' => 3]), 'exception' => 'Member status conflict during update.'],
        ];

        $failedJobs = [];
        foreach ($failedJobData as $failedJobItem) {
            $failedJobs[] = [
                'uuid' => (string) Str::uuid(),
                'connection' => 'database',
                'queue' => 'default',
                'payload' => $failedJobItem['payload'],
                'exception' => $failedJobItem['exception'],
                'failed_at' => $now,
            ];
        }
        DB::table('failed_jobs')->insert($failedJobs);

        $tokenData = [
            ['tokenable_id' => 1, 'name' => 'web-dashboard', 'token_seed' => 'web-dashboard-ayesha-2026', 'abilities' => ['*'], 'last_used_at' => null],
            ['tokenable_id' => 2, 'name' => 'android-app', 'token_seed' => 'android-app-bilal-2026', 'abilities' => ['subscriptions:read', 'wallet:write'], 'last_used_at' => $now->copy()->subHours(3)],
            ['tokenable_id' => 3, 'name' => 'ios-app', 'token_seed' => 'ios-app-sara-2026', 'abilities' => ['subscriptions:read', 'subscriptions:write'], 'last_used_at' => $now->copy()->subHours(8)],
            ['tokenable_id' => 4, 'name' => 'api-integration', 'token_seed' => 'api-integration-hamza-2026', 'abilities' => ['wallet:read', 'payouts:create'], 'last_used_at' => $now->copy()->subHour()],
            ['tokenable_id' => 5, 'name' => 'support-panel', 'token_seed' => 'support-panel-noor-2026', 'abilities' => ['users:read', 'tickets:manage'], 'last_used_at' => $now->copy()->subHours(12)],
        ];

        $accessTokens = [];
        foreach ($tokenData as $tokenItem) {
            $accessTokens[] = [
                'tokenable_type' => 'App\\Models\\User',
                'tokenable_id' => $tokenItem['tokenable_id'],
                'name' => $tokenItem['name'],
                'token' => hash('sha256', $tokenItem['token_seed']),
                'abilities' => json_encode($tokenItem['abilities']),
                'last_used_at' => $tokenItem['last_used_at'],
                'expires_at' => $now->copy()->addDays(30),
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }
        DB::table('personal_access_tokens')->insert($accessTokens);

        $this->command?->info('Inserted 5 realistic rows into each table successfully.');
    }
}
