<?php

namespace Modules\City\Models;

use Modules\City\Models\CityDescription;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Country\Models\Country;
use Modules\Region\Models\Region;
use Modules\Warehouse\Models\WarehouseCity;

class City extends Model
{
    //use soft delete
    use SoftDeletes;

    // protected $fillable = [
    //     'region_id','default_city','shipping_cost'
    // ];


    /**
     * Get current description of the the Room
     * @return HasOne
     */
    public function region()
    {
        return $this->belongsTo(Region::class)->withTrashed();
    }

    public function warehouses()
    {
        return $this->hasMany(WarehouseCity::class);
    }

    public function getWarehouseIdAttribute()
    {
        return $this->hasMany(WarehouseCity::class)->pluck('warehouse_id')->toArray();
    }

    public function currentDescription() :HasOne
    {
        return $this->hasOne(CityDescription::class)->where('language_id', config('current_language_id'));
    }
}
