<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Appends;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

#[Appends(['formatted_created_at'])]
#[Guarded(['id'])]
class FormHistory extends Model
{
    use HasFactory;

    protected function casts(): array
    {
        return [
            'attribute_changes' => 'array',
        ];
    }

    protected function formattedCreatedAt(): Attribute
    {
        return Attribute::make(
            get: fn () => $this->created_at?->translatedFormat('l, d F Y H:i'),
        );
    }

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