<?php

namespace Database\Seeders;

use App\Models\Service;
use App\Models\ServiceSubscription;
use Carbon\Carbon;
use Illuminate\Database\Seeder;

class ExpiredSubscriptionsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Get all services
        $services = Service::all();

        if ($services->isEmpty()) {
            $this->command->info('No services found. Please seed services first.');

            return;
        }

        foreach ($services as $service) {
            $this->command->info("Adding late customers for service: {$service->name}");

            // Late Customer 1 (Overdue by 10 days)
            ServiceSubscription::create([
                'service_id' => $service->id,
                'customer_name' => "مشترك متأخر 1 - {$service->name}",
                'phone' => '07800000010',
                'whatsapp' => '07800000010',
                'address' => 'Baghdad, Iraq',
                'business_name' => "Late Business 1 - {$service->type}",
                'details' => "Late subscription test 1 for {$service->name}",
                'price' => $service->price > 0 ? $service->price : 500,
                'renewal_due_date' => Carbon::now()->subDays(10),
                'renewal_amount' => $service->price > 0 ? $service->price : 500,
                'payment_method' => 'cash',
                'created_by' => 1,
                'invoice_number' => "INV-LATE-1-{$service->id}",
            ]);

            // Late Customer 2 (Overdue by 45 days)
            ServiceSubscription::create([
                'service_id' => $service->id,
                'customer_name' => "مشترك متأخر 2 - {$service->name}",
                'phone' => '07800000011',
                'whatsapp' => '07800000011',
                'address' => 'Basra, Iraq',
                'business_name' => "Late Business 2 - {$service->type}",
                'details' => "Late subscription test 2 for {$service->name}",
                'price' => $service->price > 0 ? $service->price : 1000,
                'renewal_due_date' => Carbon::now()->subDays(45),
                'renewal_amount' => $service->price > 0 ? $service->price : 1000,
                'payment_method' => 'zain_cash',
                'created_by' => 1,
                'invoice_number' => "INV-LATE-2-{$service->id}",
            ]);
        }
    }
}
