<?php

namespace Database\Seeders;

use App\Models\Loan;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        $this->call([
            PermissionSeeder::class,
            CurrencySeeder::class,
        ]);

        $this->command->info('Database seeded successfully!');
    }

    private function getRandomRemarks(): string
    {
        $remarks = [
            'Application under review',
            'Documents verified',
            'Waiting for approval',
            'Credit check completed',
            'Ready for disbursement',
            'Payment in arrears',
            'New application',
            'Follow up required'
        ];

        return $remarks[array_rand($remarks)];
    }

    private function showLoanSummary(): void
    {
        $pending = Loan::where('status', 'pending')->count();
        $processing = Loan::where('status', 'processing')->count();
        $approved = Loan::where('status', 'approved')->count();
        $arrears = Loan::where('status', 'arrears')->count();

        $cashLoans = Loan::where('loan_type', 'cash')->count();
        $productLoans = Loan::where('loan_type', 'product')->count();

        $this->command->info("Loan Status Summary:");
        $this->command->info("   - Pending: {$pending} loans");
        $this->command->info("   - Processing: {$processing} loans");
        $this->command->info("   - Approved: {$approved} loans");
        $this->command->info("   - Arrears: {$arrears} loans");

        $this->command->info("Loan Type Summary:");
        $this->command->info("   - Cash: {$cashLoans} loans");
        $this->command->info("   - Product: {$productLoans} loans");

        // Show date range
        $oldest = Loan::oldest('created_at')->first();
        $newest = Loan::latest('created_at')->first();

        if ($oldest && $newest) {
            $this->command->info("Date Range:");
            $this->command->info("   - Oldest: " . $oldest->created_at->format('M d, Y'));
            $this->command->info("   - Newest: " . $newest->created_at->format('M d, Y'));
        }
    }
}
