<?php

namespace Database\Seeders;

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

// database/seeders/DatabaseSeeder.php
namespace Database\Seeders;

use App\Models\User;
use App\Models\Tenant;
use App\Models\Outlet;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        // 1. Buat Tenant (Bisnis Utama)
        $tenant = Tenant::create([
            'uuid' => (string) Str::uuid(),
            'business_code' => 'QUEEN01',
            'business_name' => 'QueenFruits Indonesia',
            'business_type' => 'F&B - Fruit Store',
            'subscription_level' => 'standart',
        ]);

        // 2. Buat Beberapa Outlet (Untuk testing Owner yang menerima Array)
        $outletUtama = Outlet::create([
            'uuid' => (string) Str::uuid(),
            'tenant_id' => $tenant->id,
            'name' => 'QueenFruits - Pusat Kaliwates',
            'phone_number' => '08123456789',
            'is_main_outlet' => true,
        ]);

        $outletCabang = Outlet::create([
            'uuid' => (string) Str::uuid(),
            'tenant_id' => $tenant->id,
            'name' => 'QueenFruits - Cabang Sumbersari',
            'phone_number' => '08123456788',
            'is_main_outlet' => false,
        ]);

        // 3. Buat User Owner (Menerima semua outlet dalam bentuk Array)
        User::create([
            'uuid' => (string) Str::uuid(),
            'tenant_id' => $tenant->id,
            'outlet_id' => $outletUtama->id,
            'name' => 'Ali Akbar Rafsanjani',
            'email' => 'owner@niogu.com',
            'password' => Hash::make('password123'),
            'role' => 'owner',
            'is_active' => true,
        ]);

        // 4. Buat User Staff (Menerima hanya satu outlet terkait dalam bentuk Object)
        User::create([
            'uuid' => (string) Str::uuid(),
            'tenant_id' => $tenant->id,
            'outlet_id' => $outletCabang->id, // Terikat ke Cabang Sumbersari
            'name' => 'Budi Kasir',
            'phone_number' => '08123456789',
            'password' => Hash::make('password123'),
            'role' => 'admin',
            'shift_name' => 'Shift 1',
            'shift_start_time' => '08.00',
            'shift_end_time' => '14.00',
            'is_active' => true,
        ]);
    }
}
