<?php

namespace App\Support;

use App\Models\User;
use Carbon\CarbonInterface;
use Illuminate\Support\Str;

class GeneratedNames
{
    public static function campaign(string $concept, string $platform, ?User $user, ?CarbonInterface $date = null): string
    {
        $owner = Str::limit(Str::slug($user?->name ?? 'user'), 24, '').'-u'.($user?->getKey() ?? 'unknown');

        return Str::limit(Str::slug($concept) ?: 'campaign', 120, '')
            .'_'.$owner.'_'.Str::upper($platform).'_'.($date ?? now())->format('Y-m-d');
    }

    public static function creative(string $concept, string $type, string $ratio, ?CarbonInterface $date = null): string
    {
        $dimension = $type === 'image' ? match ($ratio) {
            '1:1' => '1200x1200',
            '9:16' => '900x1600',
            '16:9' => '1600x900',
            '4:5' => '960x1200',
            '1.91:1' => '1200x628',
            default => str_replace(':', 'x', $ratio),
        } : str_replace(':', 'x', $ratio);

        $suffix = '_'.ucfirst($type).'-'.$dimension.'_'.($date ?? now())->format('Y-m-d');

        return Str::limit(Str::slug($concept) ?: 'creative', 80 - Str::length($suffix), '').$suffix;
    }
}
