<?php


namespace App\Models\StockManagement\Traits;


use App\Models\StockManagement\Warehouse;
use App\Models\StockManagement\WarehouseHasManager;
use App\Models\StockManagement\WareHouseType;
use Illuminate\Database\Eloquent\Relations\HasMany;

trait CanManageWarehouse{

    /**Un user a plusieur demandes de stocks
     * @return HasMany
     */
    public function warehouses(){
        return $this->belongsToMany(
             config("stocks-management.tables.warehouse"),
             config("stocks-management.tables.warehouse-has-manager"),
           // (new WarehouseHasManager)->getTable(),
            "manager_id",
            "warehouse_id",
        );
    }

    public function warehousesPointOfSales(){
        return $this->warehouses()->pointOfSales();
    }

    public function pointOfSales(){
        return $this->belongsToMany(
                Warehouse::class,
                WarehouseHasManager::class,
                "manager_id",
                "warehouse_id",
                )
                ->where('warehouse_type_code',WareHouseType::POINT_OF_SALE);
    }

    public function stores(){
        return $this->belongsToMany(
            Warehouse::class,
            WarehouseHasManager::class,
            "manager_id",
            "warehouse_id",
                )
                ->where('warehouse_type_code',WareHouseType::STORE);
    }


}
