<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Emirate extends Model
{
    use SoftDeletes;

    protected $fillable = ['name','name_ar','country_id', 'status'];
    protected $translatable = ['name'];
    public function getAttributes()
    {
        foreach($this->translatable as $attribute) {
            $locale = app()->getLocale();
            $localizedKey = "{$attribute}_{$locale}";
            if (isset($this->attributes[$localizedKey])) {
                $this->attributes[$attribute] =  (empty($this->attributes[$localizedKey]))?$this->attributes["{$attribute}"]:$this->attributes[$localizedKey];
            }
        }
        return $this->attributes;
    }

    public function country()
    {
        return $this->belongsTo(Country::class, 'country_id', 'id');
    }
}
