<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Auth;

class District extends Model
{
    protected $table = 'm_districts';
    protected $guarded = [];

    protected static function booted(): void
    {
        static::creating(fn ($model) => $model->created_by = Auth::id());
        static::updating(fn ($model) => $model->updated_by = Auth::id());
    }

    public function city(): BelongsTo
    {
        return $this->belongsTo(City::class, 'city_id');
    }

    public function villages(): HasMany
    {
        return $this->hasMany(Village::class);
    }

    public function districts()
    {
        return $this->hasMany(District::class);
    }
}