<?php

namespace App\Models;

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

/**
 * Where one asset lives on one platform account.
 *
 * The same image uploaded to Meta and to TikTok gets a different id from each,
 * so the id cannot sit on the asset itself.
 */
#[Fillable(['asset_id', 'platform', 'ad_account_id', 'external_hash', 'external_id'])]
class AssetPlatformRef extends Model
{
    public function asset(): BelongsTo
    {
        return $this->belongsTo(Asset::class);
    }

    public function reference(): ?string
    {
        return $this->external_hash ?: $this->external_id;
    }
}
