<?php

namespace Tests\Feature;

use App\Models\Announcement;
use App\Models\NavigationMenu;
use App\Models\Slider;
use App\Models\TrustBadge;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class SiteSettingsApiTest extends TestCase
{
    use RefreshDatabase;

    /**
     * Test site-settings API returns correct structured JSON data.
     */
    public function test_site_settings_api_returns_structured_data()
    {
        // Create dummy sliders
        Slider::create([
            'title' => 'Test Slider 1',
            'subtitle' => 'Subtitle 1',
            'badge' => 'Badge 1',
            'btn_text' => 'Btn 1',
            'link_url' => '/test-url-1',
            'image' => 'sliders/test1.png',
            'type' => 'hero',
            'sort_order' => 1,
            'is_active' => true,
        ]);

        // Create dummy badges
        TrustBadge::create([
            'title' => 'Badge Title',
            'description' => 'Badge Description',
            'icon' => 'Truck',
            'sort_order' => 1,
            'is_active' => true,
        ]);

        // Create dummy announcements
        Announcement::create([
            'text' => 'Announcement Text',
            'link_url' => '/announcement-link',
            'is_active' => true,
        ]);

        // Make API call
        $response = $this->getJson('/api/site-settings');

        $response->assertStatus(200);
        $response->assertJsonStructure([
            'success',
            'data' => [
                'settings',
                'sliders' => [
                    'hero',
                    'middle',
                ],
                'trust_badges',
                'navigation' => [
                    'header',
                    'footer',
                ],
                'announcements',
            ]
        ]);

        // Assert values
        $response->assertJsonPath('success', true);
        $response->assertJsonCount(1, 'data.sliders.hero');
        $response->assertJsonCount(1, 'data.trust_badges');
        $response->assertJsonCount(1, 'data.announcements');
        $this->assertEquals('Test Slider 1', $response->json('data.sliders.hero.0.title'));
        $this->assertEquals('Badge Title', $response->json('data.trust_badges.0.title'));
        $this->assertEquals('Announcement Text', $response->json('data.announcements.0.text'));
    }
}
