<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class AmadastCity extends Model
{
    public $incrementing = false;
    protected $keyType   = 'integer';
    protected $fillable  = ['id', 'title', 'parent_id'];

    public function scopeProvinces($query)
    {
        return $query->whereNull('parent_id')->orderBy('title');
    }

    public function scopeCities($query)
    {
        return $query->whereNotNull('parent_id')->orderBy('title');
    }

    public function province()
    {
        return $this->belongsTo(self::class, 'parent_id');
    }

    public function childCities()
    {
        return $this->hasMany(self::class, 'parent_id')->orderBy('title');
    }
}
