<?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 SubscriptionType extends Model
{
    use HasFactory, HasTranslations, FilterableTrait, BlameableTrait;

    protected $fillable = [
        'name',
        'description',
        'is_active',
    ];

    public array $translatable = ['name', 'description'];

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

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

    /**
     * Relationship: Contracts
     */
    public function contracts()
    {
        return $this->hasMany(Contract::class);
    }

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