<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\Builder;

class City extends Model
{
    use HasFactory;

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

    protected $casts = [
        'is_active' => 'boolean',
    ];

    final public function scopeActive(Builder $query, bool $active = true): Builder
    {
        return $query->where('is_active', $active);
    }

    final public function scopeInactive(Builder $query, bool $active = false): Builder
    {
        return $query->where('is_active', $active);
    }

    final public function postalCodes(): HasMany
    {
        return $this->hasMany(PostalCode::class);
    }
}
