<?php

namespace Database\Seeders;

use App\Models\ApprovalStep;
use App\Models\ApprovalWorkflow;
use App\Models\TravelRequest;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        // Create roles
        $this->call(RoleSeeder::class);

        // Create admin user
        $admin = User::factory()->create([
            'name' => 'Administrator',
            'email' => 'admin@example.com',
            'username' => 'admin',
            'password' => Hash::make('password'),
        ]);
        $admin->assignRole('administrator');

        // Create a travel approver
        $approver = User::factory()->create([
            'name' => 'Travel Approver',
            'email' => 'approver@example.com',
            'username' => 'approver',
            'password' => Hash::make('password'),
        ]);
        $approver->assignRole('travel_approver');

        // Create a staff user
        $staff = User::factory()->create([
            'name' => 'Staff Member',
            'email' => 'staff@example.com',
            'username' => 'staff',
            'password' => Hash::make('password'),
        ]);
        $staff->assignRole('staff');

        // Create default approval workflow with 2 steps
        $workflow = ApprovalWorkflow::create([
            'name' => 'Standard Travel Approval',
            'description' => 'Default two-step travel approval workflow',
            'is_active' => true,
        ]);

        ApprovalStep::create([
            'workflow_id' => $workflow->id,
            'order' => 1,
            'name' => 'Travel Approver Review',
            'role' => 'travel_approver',
        ]);

        ApprovalStep::create([
            'workflow_id' => $workflow->id,
            'order' => 2,
            'name' => 'Administrator Final Approval',
            'role' => 'administrator',
        ]);

        // Create sample travel requests for staff
        TravelRequest::factory(3)->create([
            'user_id' => $staff->id,
        ]);
    }
}
