<?php

use App\Filament\Resources\Entries\EntryResource;
use App\Models\Entry;

it('references the correct model and record title attribute', function () {
    $defaults = (new ReflectionClass(EntryResource::class))->getDefaultProperties();

    expect($defaults['model'] ?? null)->toBe(Entry::class);
    expect($defaults['recordTitleAttribute'] ?? null)->toBe('title');
});

it('defines the expected pages', function () {
    $pages = EntryResource::getPages();

    expect(array_keys($pages))->toEqual(['index', 'create', 'view', 'edit']);
});

it('accepts new record when entered via the form schema', function () {

    $data = [
        'title' => 'Test Entry',
        'slug' => 'test-entry',
        'description' => 'This is a test entry.',
        'is_published' => true,
        'is_featured' => false,
        'published_at' => now()->toDateString(),
        'content' => '<p>This is the content of the test entry.</p>',
    ];

    $entry = new Entry();
    $entry->fill($data);
 
    expect($entry->slug)->toBe('test-entry');
});

it('deletes a record correctly', function () {
    $entry = Entry::create([
        'title' => 'Test Entry to Delete',
        'slug' => 'test-entry-to-delete',
        'description' => 'This is a test entry.',
        'is_published' => false,
        'is_featured' => false,
        'published_at' => null,
        'content' => '<p>This is the content of the test entry.</p>',
    ]);

    $entryId = $entry->id;
    $entry->delete();

    $deletedEntry = Entry::find($entryId);
    expect($deletedEntry)->toBeNull();
});