<?php

namespace App\DTOs;

use Illuminate\Support\Str;

readonly class PromptLandingPageBrief
{
    /**
     * @param  list<string>  $features
     * @param  list<string>  $benefits
     * @param  list<string>  $usps
     * @param  list<string>  $painPoints
     */
    public function __construct(
        public string $brandName,
        public string $offering,
        public array $features,
        public array $benefits,
        public string $pricing,
        public string $audience,
        public array $usps,
        public array $painPoints,
        public string $tone,
        public string $cta,
        public string $headline,
        public ?string $notes,
        public string $purpose = '',
        public string $primaryColor = '',
        public string $secondaryColor = '',
        public string $accentColor = '',
        public string $backgroundColor = '',
        public string $textColor = '',
        public bool $logoPresent = false,
        public string $logoType = 'unknown',
        public string $logoWordmarkText = '',
        public string $logoDescription = '',
        public string $logoExactSvg = '',
        public string $logoUrl = '',
        public string $faviconUrl = '',
        public string $fontFamily = '',
        public string $fontStylesheetUrl = '',
    ) {}

    /**
     * @param  array<string, mixed>  $data
     */
    public static function fromArray(array $data): self
    {
        $logoType = Str::lower((string) ($data['logo_type'] ?? 'unknown'));

        if (! in_array($logoType, ['wordmark', 'icon', 'combination-mark', 'unknown'], true)) {
            $logoType = 'unknown';
        }

        return new self(
            brandName: (string) ($data['brand_name'] ?? ''),
            offering: (string) ($data['offering'] ?? $data['product_name'] ?? ''),
            features: array_values(array_filter((array) ($data['features'] ?? []))),
            benefits: array_values(array_filter((array) ($data['benefits'] ?? []))),
            pricing: (string) ($data['pricing'] ?? ''),
            audience: (string) ($data['audience'] ?? ''),
            usps: array_values(array_filter((array) ($data['usps'] ?? []))),
            painPoints: array_values(array_filter((array) ($data['pain_points'] ?? []))),
            tone: (string) ($data['tone'] ?? ''),
            cta: (string) ($data['cta'] ?? ''),
            headline: (string) ($data['headline'] ?? ''),
            notes: isset($data['notes']) ? (string) $data['notes'] : null,
            purpose: (string) ($data['purpose'] ?? ''),
            primaryColor: (string) ($data['primary_color'] ?? ''),
            secondaryColor: (string) ($data['secondary_color'] ?? ''),
            accentColor: (string) ($data['accent_color'] ?? ''),
            backgroundColor: (string) ($data['background_color'] ?? ''),
            textColor: (string) ($data['text_color'] ?? ''),
            logoPresent: (bool) ($data['logo_present'] ?? false),
            logoType: $logoType,
            logoWordmarkText: (string) ($data['logo_wordmark_text'] ?? ''),
            logoDescription: (string) ($data['logo_description'] ?? ''),
            logoExactSvg: (string) ($data['logo_exact_svg'] ?? ''),
            logoUrl: (string) ($data['logo_url'] ?? ''),
            faviconUrl: (string) ($data['favicon_url'] ?? ''),
            fontFamily: (string) ($data['font_family'] ?? ''),
            fontStylesheetUrl: (string) ($data['font_stylesheet_url'] ?? ''),
        );
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'brand_name' => $this->brandName,
            'offering' => $this->offering,
            'features' => $this->features,
            'benefits' => $this->benefits,
            'pricing' => $this->pricing,
            'audience' => $this->audience,
            'usps' => $this->usps,
            'pain_points' => $this->painPoints,
            'tone' => $this->tone,
            'cta' => $this->cta,
            'headline' => $this->headline,
            'notes' => $this->notes,
            'purpose' => $this->purpose,
            'primary_color' => $this->primaryColor,
            'secondary_color' => $this->secondaryColor,
            'accent_color' => $this->accentColor,
            'background_color' => $this->backgroundColor,
            'text_color' => $this->textColor,
            'logo_present' => $this->logoPresent,
            'logo_type' => $this->logoType,
            'logo_wordmark_text' => $this->logoWordmarkText,
            'logo_description' => $this->logoDescription,
            'logo_exact_svg' => $this->logoExactSvg,
            'logo_url' => $this->logoUrl,
            'favicon_url' => $this->faviconUrl,
            'font_family' => $this->fontFamily,
            'font_stylesheet_url' => $this->fontStylesheetUrl,
        ];
    }
}
