<?php

namespace App\Models;

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

/** One ad: an asset plus the words around it, in one ad set. */
#[Fillable([
    'campaign_id', 'ad_set_id', 'asset_id', 'headline', 'primary_text', 'description',
    'cta', 'external_creative_id', 'external_ad_id', 'status',
])]
class CampaignAd extends Model
{
    public function campaign(): BelongsTo
    {
        return $this->belongsTo(Campaign::class);
    }

    /**
     * The ad set this ad runs in.
     *
     * Null on every ad written before ad sets were rows, and those were all in
     * their campaign's only ad set, so callers read null as the first one rather
     * than as "no ad set".
     */
    public function adSet(): BelongsTo
    {
        return $this->belongsTo(CampaignAdSet::class, 'ad_set_id');
    }

    public function asset(): BelongsTo
    {
        return $this->belongsTo(Asset::class);
    }
}
