<?php

namespace Database\Seeders;

use App\Enums\Day;
use App\Enums\OutletStatus;
use App\Models\OpeningHour;
use App\Models\Outlet;
use Illuminate\Database\Seeder;

class OutletSeeder extends Seeder
{
    public function run(): void
    {
        $outlets = [
            [
                'name' => 'Toko 1',
                'slug' => 'toko-1',
                'phone_number' => '085135557595',
                'address' => 'Jl. Taman Pahlawan No.41, Nagri Kaler, Kec. Purwakarta, Kabupaten Purwakarta, Jawa Barat 41119',
                'landmark' => 'Samping Gacoan',
            ],
            [
                'name' => 'Outlet 2',
                'slug' => 'outlet-2',
                'phone_number' => '085135557595',
                'address' => 'Jl. Ipik Gandamanah, Kabupaten Purwakarta, Jawa Barat 41117',
                'landmark' => 'Samping Global Bakery',
            ],
            [
                'name' => 'Outlet 3',
                'slug' => 'outlet-3',
                'phone_number' => '085135557595',
                'address' => 'Pabuaran, Subang Regency, West Java',
                'landmark' => null,
            ],
            [
                'name' => 'Outlet 4',
                'slug' => 'outlet-4',
                'phone_number' => '085135557595',
                'address' => 'Jl. Raya Citeko, Pamoyanan, Kec. Plered, Kabupaten Purwakarta, Jawa Barat',
                'landmark' => null,
            ],
        ];

        foreach ($outlets as $data) {
            $outlet = Outlet::create([
                ...$data,
                'status' => OutletStatus::OPERATIONAL,
                'opened_date' => now()->toDateString(),
            ]);

            $hours = collect(Day::cases())->map(fn ($day) => [
                'outlet_id' => $outlet->id,
                'day' => $day->value,
                'open_time' => '09:00:00',
                'close_time' => '21:00:00',
            ])->toArray();

            $outlet->facilities()->create(['name' => 'Parkir']);

            OpeningHour::insert($hours);
        }
    }
}
