<?php

namespace App\Models\OrderManagement;

use App\Models\ProductManagement\Product;
use App\Models\StockManagement\Traits\CanAdjustStock;
use App\Models\StockManagement\Traits\HasOutputs;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OrderProduct extends Model{
    use HasFactory,HasOutputs,CanAdjustStock;

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

    public $timestamps = false;
    public $incrementing = true;
    protected $primaryKey = "id";

    // protected $appends = [
    //     'amount',
    // ];


    public function product(){
        return $this->belongsTo(Product::class,"product_id");
    }

    public function order(){
        return $this->belongsTo(Order::class,"order_id");
    }

    //SCOPES

    public function scopeNoRejected($query){
        return $query->where("rejected",false);
    }
    public function scopeRejected($query){
        return $query->where("rejected",true);
    }


    //GETTERS
    public function getWarehouseAttribute(){
        return $this->order->warehouse;
    }
    // public function getAmountAttribute(){
    //     return $this->quantity * $this->price;
    // }

}
