<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

#[Fillable(['name', 'gender', 'accent', 'type', 'source_path', 'provider_ref', 'meta'])]
class Avatar extends Model
{
    protected function casts(): array
    {
        return [
            'meta' => 'array',
        ];
    }

    public function creatives(): HasMany
    {
        return $this->hasMany(Creative::class);
    }

    /**
     * Detailed character DNA for video prompt synthesis, matching the stock photo thumbnail.
     */
    public function visualDescription(): string
    {
        if (! empty($this->meta['visual_description'])) {
            return (string) $this->meta['visual_description'];
        }

        $name = strtolower((string) $this->name);

        $descriptions = [
            'ava' => 'a charismatic 29-year-old woman with warm hazel eyes, shoulder-length wavy chestnut hair, radiant natural skin texture, wearing a tailored slate-gray linen blazer over a crisp ivory scoop-neck top',
            'liam' => 'a sharp, articulate 31-year-old man with neatly groomed short brown hair, well-trimmed stubble beard, confident posture, wearing a fitted navy crewneck sweater',
            'sofia' => 'an elegant 30-year-old woman with sleek dark brunette hair parted in the middle, refined posture, wearing an olive tailored blouse with subtle gold stud earrings',
            'noah' => 'a sharp 29-year-old British man with neat side-parted dark hair, engaging warm smile, wearing a structured charcoal knit polo',
            'priya' => 'a poised 28-year-old South Asian woman with glowing warm skin, long dark brown hair styled naturally, wearing a stylish terracotta blazer',
            'diego' => 'an energetic 30-year-old Latino man with expressive dark eyes, stylish short textured dark hair, wearing a clean crisp white collared shirt with rolled cuffs',
            'mei' => 'a vibrant 27-year-old East Asian woman with shoulder-length straight glossy black hair, warm engaging smile, wearing a modern sage green cardigan',
            'ethan' => 'a trustworthy 33-year-old Canadian man with wavy sandy-brown hair, clear blue eyes, wearing a classic heather-gray chambray shirt',
            'zainab' => 'a radiant 28-year-old Black woman with glowing rich dark skin, elegantly styled braided updo, wearing a bright mustard-yellow tailored blazer',
            'kenji' => 'a modern 32-year-old Japanese man with stylish clean-cut dark hair, minimalist black designer glasses, wearing a sleek matte-black crewneck',
            'isla' => 'an approachable 27-year-old Scottish woman with natural reddish-auburn hair, light freckles, bright green eyes, wearing a cozy cream cable-knit sweater',
            'marcus' => 'a charismatic 34-year-old Black man with a close-trimmed fade haircut, warm confident smile, wearing a sharp deep-burgundy henley',
        ];

        return $descriptions[$name] ?? sprintf('a professional, polished %s presenter with natural styling, authentic warm smile, and clean contemporary wardrobe', $this->gender ?? 'commercial');
    }
}
