<?php

namespace Database\Seeders;

use App\Enums\EmploymentStatus;
use App\Enums\Gender;
use App\Enums\UserRole;
use App\Models\Employee;
use App\Models\Outlet;
use App\Models\ReferralCode;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        $outlet_ids = Outlet::all()->pluck('id')->toArray();

        // developer
        $developer = User::create([
            'email' => 'project.pangestuyoga@gmail.com',
            'username' => 'pangestu',
            'password' => Hash::make(config('myconfig.password_default')),
        ]);

        Employee::create([
            'user_id' => $developer->id,
            'code' => '0001',
            'full_name' => 'Yoga Pangestu',
            'phone_number' => '082121495806',
            'gender' => Gender::MALE,
            'address' => 'Kp. Bakan Sampeu',
            'birthdate' => '2005-03-13',
            'hire_date' => now(),
            'status' => EmploymentStatus::PERMANENT,
        ]);

        ReferralCode::create([
            'user_id' => $developer->id,
            'code' => generateReferralCode('pangestu', 1),
        ]);

        $developer->assignRole(UserRole::Developer);
        $developer->outlets()->attach($outlet_ids);

        // owner
        $owner = User::create([
            'email' => 'mulyadi@gmail.com',
            'username' => 'mulyadi',
            'password' => Hash::make(config('myconfig.password_default')),
        ]);

        Employee::create([
            'user_id' => $owner->id,
            'code' => '0002',
            'full_name' => 'Yadi Mulyadi',
            'phone_number' => '082121495806',
            'gender' => Gender::MALE,
            'address' => 'Kp. Bakan Sampeu',
            'birthdate' => '2000-01-01',
            'hire_date' => now(),
            'status' => EmploymentStatus::PERMANENT,
        ]);

        ReferralCode::create([
            'user_id' => $owner->id,
            'code' => generateReferralCode('mulyadi', 1),
        ]);

        $owner->assignRole(UserRole::Owner);
        $owner->outlets()->attach($outlet_ids);
    }
}
