<?php

namespace App\Services\Meta;

/** One ad creative: an image, a destination, and the words around it. */
readonly class CreativeSpec
{
    public function __construct(
        public string $adAccountId,
        public string $pageId,
        public string $imageHash,
        public string $landingUrl,
        public string $headline,
        public string $primaryText,
        public string $callToAction,
        public string $name,
        public string $description = '',
    ) {}

    /** The Graph API shape. */
    public function storySpec(): array
    {
        return [
            'page_id' => $this->pageId,
            'link_data' => [
                'image_hash' => $this->imageHash,
                'link' => $this->landingUrl,
                'message' => $this->primaryText,
                'name' => $this->headline,
                'description' => $this->description,
                'call_to_action' => [
                    'type' => $this->callToAction,
                    'value' => ['link' => $this->landingUrl],
                ],
            ],
        ];
    }

    /** The MCP shape, which is flat and uses different names for the same things. */
    public function mcpArguments(): array
    {
        return [
            'ad_account_id' => ltrim(str_replace('act_', '', $this->adAccountId), '_'),
            'page_id' => $this->pageId,
            'image_hash' => $this->imageHash,
            'link_url' => $this->landingUrl,
            'message' => $this->primaryText,
            'headline' => $this->headline,
            'description' => $this->description,
            'call_to_action_type' => $this->callToAction,
            'name' => $this->name,
        ];
    }
}
