<?php

namespace App\Models\OrderManagement;

use App\Models\LocalizationManagement\Country;
use App\Models\Traits\Activable;
use App\Models\Traits\Bootables\Auditable;
use Axn\EloquentAuthorable\AuthorableTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Nicolaslopezj\Searchable\SearchableTrait;

class ShippingCompany extends Model {
    use HasFactory, SearchableTrait,Activable,AuthorableTrait,Auditable;

    protected $table = "order_mgt__shipping_companies";
    protected $guarded = ["id"];

    protected $searchable = [
        'columns' => [
            'shipping_companies.name' => 10,
            'shipping_companies.code' => 10,
            'shipping_companies.description' => 10
        ],
    ];


    /**
     * @return array|string|null
     */
    public function getFastNameAttribute(){
        return ($this->attributes['fast'])
               ? __("Fast Delivery")
              : __('Normal Delivery');
    }

    public function getIsFastAttribute(){
        return ($this->attributes['fast'])
            ? __("Yes")
            : __('No');
    }

    /**
     * @return BelongsToMany
     */
    public function countries(){
        return $this->belongsToMany(
            Country::class,
            (new ShippingCompanyHasCountry)->getTable(),
            "shipping_company_id",
            "country_id"
        );
    }

    /**
     * @return HasMany
     */
    public function orders(){
        return $this->hasMany(Order::class,"shipping_company_id");
    }
}
