<?php

namespace App\Models;

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

class City extends Model
{
    use HasFactory;
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'name_en',
        'feature_id',
        'province_feature_id',
        'center_lat',
        'center_long',
        'created_at',
        'updated_at'
    ];

    public function province()
    {
        return $this->belongsTo('App\Models\Province');
    }

    public function users()
    {
        return $this->hasMany('App\Models\User');
    }
    
    /**
     * Get all of the projects for the city.
     */
    public function roadConstructionProjects()
    {
        return $this->hasManyThrough('App\Models\RoadConstructionProject', 'App\Models\User');
    }

    /**
     * Get all of the projects for the city.
     */
    public function roadItemsProjects()
    {
        return $this->hasManyThrough('App\Models\RoadItemsProject', 'App\Models\User');
    }

    /**
     * Get all of the projects for the city.
     */
    public function roadPatrolProjects()
    {
        return $this->hasManyThrough('App\Models\RoadPatrolProject', 'App\Models\User');
    }

    /**
     * Get all of the projects for the province.
     */
    public function roadMaintenanceProjects()
    {
        return $this->hasMany('App\Models\RoadMaintenanceProject');
    }
        /**
     * Get all of the projects for the province.
     */
    public function roadConstructionRural()
    {
        return $this->hasMany('App\Models\RoadConstructionRural');
    }

    public function edarateShahri()
    {
        return $this->belongsToMany('App\Models\EdarateShahri', 'edarate_shahri_be_city')->withPivot('is_primary','id');
    }
}
