<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;

class Zona extends Model
{
    use LogsActivity;

    protected $table = 'zone';

    protected $fillable = ['nome', 'attivo'];

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

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logOnly(['nome', 'attivo'])
            ->logOnlyDirty()
            ->dontSubmitEmptyLogs();
    }

    public function territori()
    {
        return $this->hasMany(Territorio::class, 'zona_id');
    }

    public function scopeAttive($query)
    {
        return $query->where('attivo', true);
    }
}
