<?php

namespace App\Models;

use App\Traits\BlameableTrait;
use App\Traits\FilterableTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class ContractSetting extends Model
{
    use HasFactory, HasTranslations, FilterableTrait, BlameableTrait;

    protected $fillable = [
        'key',
        'title',
        'content',
        'is_active',
    ];

    public array $translatable = ['title', 'content'];

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
            'title'     => 'array',
            'content'   => 'array',
        ];
    }

    // Filterable configuration
    protected array $filterable = ['key', 'is_active'];
    protected array $searchable = ['key', 'title'];
    protected array $sortable   = ['id', 'key', 'created_at'];

    /**
     * Scope: Only active
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /**
     * Scope: By key
     */
    public function scopeByKey($query, string $key)
    {
        return $query->where('key', $key);
    }
}
