<?php

namespace Tests\Unit\Services\Staff;

use App\Services\Staff\StaffTimeOffLinkService;
use Tests\TestCase;

class StaffTimeOffLinkServiceTest extends TestCase
{
    public function test_token_round_trip(): void
    {
        $service = new StaffTimeOffLinkService('secret', 3600);

        $token = $service->createToken(['uid' => 10, 'email' => 'staff@example.com']);
        $payload = $service->parseToken($token);

        $this->assertNotNull($payload);
        $this->assertSame(10, $payload['uid']);
        $this->assertSame('staff@example.com', $payload['email']);
    }

    public function test_token_invalid_on_expiry(): void
    {
        $service = new StaffTimeOffLinkService('secret', 1);

        $token = $service->createToken(['uid' => 10]);
        sleep(2);
        $payload = $service->parseToken($token);

        $this->assertNull($payload);
    }
}
