<?php

use App\Http\Resources\HolidayResource;
use App\Models\Holiday;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Tests\TestCase;

uses(TestCase::class, RefreshDatabase::class);

test('holiday resource wraps data', function () {
    $holiday = Holiday::create([
        'date' => '2026-02-14',
        'name' => 'Test Holiday',
        'description' => 'Description',
    ]);

    $response = (new HolidayResource($holiday))->toResponse(Request::create('/'));
    $payload = $response->getData(true);

    expect($payload['data']['name'])->toBe('Test Holiday');
});

test('holiday resource collection uses data wrapper', function () {
    Holiday::create(['date' => '2026-02-14', 'name' => 'Day One', 'description' => null]);
    Holiday::create(['date' => '2026-03-01', 'name' => 'Day Two', 'description' => null]);

    $response = HolidayResource::collection(Holiday::limit(2)->get())->toResponse(Request::create('/'));
    $payload = $response->getData(true);

    expect($payload['data'])->toHaveCount(2);
});
