<?php

namespace App\Models;

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

/**
 * One change pushed to a live campaign.
 *
 * Records intent rather than transport, which api_calls already covers. This is
 * what the cooldown and the daily change limit count, and what shows a human
 * exactly what an edit did.
 */
#[Fillable(['campaign_id', 'actor', 'changes', 'state', 'error', 'applied_at'])]
class CampaignChange extends Model
{
    protected function casts(): array
    {
        return [
            'changes' => 'array',
            'applied_at' => 'datetime',
        ];
    }

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