<?php

namespace Tests\Unit\DTOs;

use App\DTOs\CatalogPageData;
use Tests\TestCase;

class CatalogPageDataTest extends TestCase
{
    public function test_it_round_trips_the_catalog_json_shape(): void
    {
        $payload = [
            'Brand' => 'peptide-serums-v2',
            'advertiser_id' => '15881',
            'campaign_id' => '122609',
            'subcategory' => 'Peptide Serums',
            'category' => 'Skincare',
            'updated' => 'May 2026',
            'hero_title' => 'Find the right peptide serum.',
            'review_sources' => [
                [
                    'name' => 'Who What Wear',
                    'url' => 'https://www.whowhatwear.com/example',
                    'angle' => 'Ranked peptide roundup',
                ],
            ],
            'products' => [
                [
                    'name' => 'Medik8 Liquid Peptides',
                    'brand' => 'Medik8',
                    'best_for' => 'Best Overall Value',
                    'price' => '$94.00',
                    'list_price' => null,
                    'discount' => null,
                    'rating' => '4.7',
                    'review_count' => '2,000',
                    'price_history' => null,
                    'image_url' => 'https://cdn.example.com/medik8.jpg',
                    'retailer_url' => 'https://example.com/medik8',
                    'chips' => ['Who What Wear #1'],
                    'convertibility' => null,
                    'certification' => null,
                    'summary' => 'A lightweight peptide serum.',
                    'summary_short' => 'A top editorial pick.',
                    'why_it_stands_out' => 'Editorial and shopper validation.',
                    'why_short' => 'Accessible price.',
                    'pros' => ['Lowest price in the lineup'],
                    'cons' => ['Single-serum approach'],
                    'tradeoff_note' => 'Best value, not the richest formula.',
                    'sources_note' => 'Who What Wear #1.',
                ],
            ],
        ];

        $catalog = CatalogPageData::fromArray($payload);

        $this->assertSame('peptide-serums-v2', $catalog->brand);
        $this->assertSame('Find the right peptide serum.', $catalog->heroTitle);
        $this->assertCount(1, $catalog->products);
        $this->assertSame('Medik8 Liquid Peptides', $catalog->products[0]->name);
        $this->assertSame($payload, $catalog->toArray());
        $this->assertTrue(CatalogPageData::isComplete($payload));
        $this->assertFalse(CatalogPageData::isComplete(['advertiser_id' => '15881']));
        $this->assertFalse(CatalogPageData::isComplete([
            'research' => [
                'products' => [
                    ['name' => 'Tent', 'url' => 'https://example.com/tent'],
                ],
            ],
        ]));
    }
}
