<?php

namespace Tests\Feature;

use App\Models\Applicant;
use App\Models\Application;
use App\Models\JobListing;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;

class HomeAppliedLabelTest extends TestCase
{
    use DatabaseTransactions;

    public function test_logged_in_applicant_sees_applied_label_on_job_card(): void
    {
        $applicant = Applicant::create([
            'name' => 'Pelamar Label',
            'email' => 'pelamar.label@example.com',
            'whatsapp' => '081111111111',
            'education' => 'S1',
            'password' => 'rahasia123',
        ]);

        $appliedJob = JobListing::create([
            'title' => 'Posisi Label Applied',
            'company' => 'PT Label',
            'location' => 'Bandung',
            'type' => 'Full-time',
            'requirements' => 'Syarat basic',
            'description' => 'Deskripsi lowongan untuk test label.',
            'is_active' => true,
            'deadline' => now()->addDays(7),
        ]);

        Application::create([
            'applicant_id' => $applicant->id,
            'job_listing_id' => $appliedJob->id,
            'status' => 'applied',
            'current_stage' => 0,
            'applied_at' => now()->subHour(),
        ]);

        $response = $this->withSession([
            'applicant_id' => $applicant->id,
        ])->get(route('home'));

        $response->assertOk();
        $response->assertSee('Posisi Label Applied');
        $response->assertSee('Anda sudah melamar posisi ini');
    }

    public function test_guest_does_not_see_applied_label(): void
    {
        JobListing::create([
            'title' => 'Posisi Tanpa Label',
            'company' => 'PT Guest',
            'location' => 'Jakarta',
            'type' => 'Full-time',
            'requirements' => 'Syarat basic',
            'description' => 'Deskripsi lowongan untuk guest.',
            'is_active' => true,
            'deadline' => now()->addDays(7),
        ]);

        $response = $this->get(route('home'));

        $response->assertOk();
        $response->assertDontSee('Anda sudah melamar posisi ini');
    }
}
