<?php

namespace Database\Seeders;

use App\Models\Customer;
use App\Models\CustomerAddress;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class CustomerSeeder extends Seeder
{
    public function run(): void
    {
        $customers = [
            [
                'first_name' => 'Carlos',
                'last_name' => 'Mendes',
                'email' => 'cliente@lkfashion.com',
                'password' => Hash::make('password123'),
                'phone' => '+258 84 100 0001',
                'gender' => 'male',
                'is_active' => true,
                'accepts_marketing' => true,
                'total_orders' => 5,
                'total_spent' => 8500.00,
            ],
            [
                'first_name' => 'Ana',
                'last_name' => 'Silva',
                'email' => 'ana.silva@email.com',
                'password' => Hash::make('password123'),
                'phone' => '+258 84 200 0002',
                'gender' => 'female',
                'birth_date' => '1992-05-15',
                'is_active' => true,
                'accepts_marketing' => true,
                'total_orders' => 12,
                'total_spent' => 15200.00,
            ],
            [
                'first_name' => 'Pedro',
                'last_name' => 'Santos',
                'email' => 'pedro.santos@email.com',
                'password' => Hash::make('password123'),
                'phone' => '+258 84 300 0003',
                'gender' => 'male',
                'birth_date' => '1988-10-20',
                'is_active' => true,
                'accepts_marketing' => false,
                'total_orders' => 8,
                'total_spent' => 11400.00,
            ],
            [
                'first_name' => 'Maria',
                'last_name' => 'Costa',
                'email' => 'maria.costa@email.com',
                'password' => Hash::make('password123'),
                'phone' => '+258 84 400 0004',
                'gender' => 'female',
                'birth_date' => '1995-03-08',
                'is_active' => true,
                'accepts_marketing' => true,
                'total_orders' => 3,
                'total_spent' => 4200.00,
            ],
        ];

        foreach ($customers as $customerData) {
            $customer = Customer::create($customerData);

            // Add addresses
            CustomerAddress::create([
                'customer_id' => $customer->id,
                'label' => 'Casa',
                'address_line1' => 'Av. Julius Nyerere, ' . rand(100, 999),
                'city' => 'Maputo',
                'state' => 'Maputo',
                'zip_code' => '1100',
                'country' => 'Moçambique',
                'phone' => $customer->phone,
                'is_default' => true,
            ]);

            // Some customers have work address
            if (rand(0, 1)) {
                CustomerAddress::create([
                    'customer_id' => $customer->id,
                    'label' => 'Trabalho',
                    'address_line1' => 'Av. da Independência, ' . rand(100, 999),
                    'city' => 'Maputo',
                    'state' => 'Maputo',
                    'zip_code' => '1150',
                    'country' => 'Moçambique',
                    'phone' => $customer->phone,
                    'is_default' => false,
                ]);
            }
        }
    }
}
