<?php

namespace Database\Seeders;

use App\Models\User;
use App\Models\Store;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        // Super Admin
        User::create([
            'name' => 'Super Administrador',
            'email' => 'admin@lkfashion.com',
            'password' => Hash::make('password123'),
            'role' => 'super_admin',
            'store_id' => null,
            'is_active' => true,
        ]);

        // Get stores
        $store1 = Store::where('code', 'LK001')->first();
        $store2 = Store::where('code', 'LK002')->first();
        $store3 = Store::where('code', 'LK003')->first();

        // Managers
        if ($store1) {
            User::create([
                'name' => 'João Silva',
                'email' => 'manager0@lkfashion.com',
                'password' => Hash::make('password123'),
                'role' => 'manager',
                'store_id' => $store1->id,
                'phone' => '+258 84 111 1111',
                'is_active' => true,
            ]);

            // Sellers for Store 1
            User::create([
                'name' => 'Maria Santos',
                'email' => 'seller01@lkfashion.com',
                'password' => Hash::make('password123'),
                'role' => 'seller',
                'store_id' => $store1->id,
                'phone' => '+258 84 222 2222',
                'is_active' => true,
            ]);

            User::create([
                'name' => 'Pedro Costa',
                'email' => 'seller02@lkfashion.com',
                'password' => Hash::make('password123'),
                'role' => 'seller',
                'store_id' => $store1->id,
                'phone' => '+258 84 333 3333',
                'is_active' => true,
            ]);
        }

        if ($store2) {
            User::create([
                'name' => 'Ana Oliveira',
                'email' => 'manager1@lkfashion.com',
                'password' => Hash::make('password123'),
                'role' => 'manager',
                'store_id' => $store2->id,
                'phone' => '+258 84 444 4444',
                'is_active' => true,
            ]);

            User::create([
                'name' => 'Carlos Mendes',
                'email' => 'seller03@lkfashion.com',
                'password' => Hash::make('password123'),
                'role' => 'seller',
                'store_id' => $store2->id,
                'phone' => '+258 84 555 5555',
                'is_active' => true,
            ]);
        }

        if ($store3) {
            User::create([
                'name' => 'Sofia Fernandes',
                'email' => 'manager2@lkfashion.com',
                'password' => Hash::make('password123'),
                'role' => 'manager',
                'store_id' => $store3->id,
                'phone' => '+258 84 666 6666',
                'is_active' => true,
            ]);

            User::create([
                'name' => 'Miguel Pereira',
                'email' => 'seller04@lkfashion.com',
                'password' => Hash::make('password123'),
                'role' => 'seller',
                'store_id' => $store3->id,
                'phone' => '+258 84 777 7777',
                'is_active' => true,
            ]);
        }
    }
}
