<?php

namespace Modules\Cms\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Modules\Cms\Database\Factories\CmsPageFactory;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;

class CmsPage extends Model
{
    /** @use HasFactory<CmsPageFactory> */
    use HasFactory, LogsActivity;

    /**
     * Full CRUD audit trail — CMS content writes are staff-only and
     * infrequent, so logging every attribute change is affordable
     * (domain.md §6; T6.2).
     */
    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logFillable()
            ->logOnlyDirty()
            ->dontLogEmptyChanges()
            ->useLogName('cms');
    }

    /**
     * @var list<string>
     */
    protected $fillable = [
        'page',
        'title',
        'mm_title',
        'meta_tags',
        'meta_keywords',
        'content',
        'mm_content',
        'is_active',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
        ];
    }
}
