<?php


namespace App\Models\OrderManagement;


use App\Models\LocalizationManagement\Bootables\Addressable;
use App\Models\Traits\Activable;
use App\Models\Traits\Bootables\Auditable;
use App\Models\UserManagement\Admin;
use Axn\EloquentAuthorable\AuthorableTrait;
use Database\Factories\CashierFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BillingDesk extends Model {

    use Hasfactory, Addressable, Activable,Auditable,SoftDeletes,AuthorableTrait;

    protected $table = "order_mgt__billing_desks";
    protected $guarded = [];

    protected $appends = [
        "managers_ids"
    ];

    protected static function newFactory(){
        return CashierFactory::new();
    }


    // RELATIONS
    public function managers(){
        return $this->belongsToMany(
            Admin::class,
            (new BillingDeskHasUser)->getTable(),
            "billing_desk_id",
            "manager_id"
        );
    }


    //GETTERS
    public function getManagersIdsAttribute(){
        return $this->managers->pluck('id')->toArray();
    }


}
