<?php

namespace Tests\Feature\Jobs;

use App\Enums\TravelStatus;
use App\Jobs\SendApprovalDecisionEmail;
use App\Mail\ApprovalDecisionMail;
use App\Models\TravelRequest;
use App\Models\User;
use Database\Seeders\RoleSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;

class SendApprovalDecisionEmailTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed(RoleSeeder::class);
    }

    public function test_decision_email_is_sent_to_applicant(): void
    {
        Mail::fake();

        $staff = User::factory()->create();
        $request = TravelRequest::factory()->approved()->create(['user_id' => $staff->id]);

        (new SendApprovalDecisionEmail($request))->handle();

        Mail::assertQueued(ApprovalDecisionMail::class, fn ($mail) => $mail->hasTo($staff->email));
    }

    public function test_rejection_email_is_sent_to_applicant(): void
    {
        Mail::fake();

        $staff = User::factory()->create();
        $request = TravelRequest::factory()->rejected()->create(['user_id' => $staff->id]);

        (new SendApprovalDecisionEmail($request))->handle();

        Mail::assertQueued(ApprovalDecisionMail::class, fn ($mail) => $mail->hasTo($staff->email));
    }
}
