<?php

namespace App\Models;

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

class City extends Model
{
    use HasFactory;
    protected $fillable = ['name_sw', 'name_en', 'region', 'lat', 'lng', 'is_active'];

    protected function casts(): array
    {
        return ['is_active' => 'boolean', 'lat' => 'decimal:7', 'lng' => 'decimal:7'];
    }

    public function tripsFrom(): HasMany
    {
        return $this->hasMany(Trip::class, 'from_city_id');
    }

    public function tripsTo(): HasMany
    {
        return $this->hasMany(Trip::class, 'to_city_id');
    }

    public function corridorsFrom(): HasMany
    {
        return $this->hasMany(Corridor::class, 'from_city_id');
    }
}
