<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Cart extends Model
{
    use HasFactory;

    protected $fillable = ['item_id', 'price','is_checked', 'item_variant_id', 'item_reference_id', 'user_id', 'qty','location_id'];

    public function item()
    {
        return $this->belongsTo(Items::class,"item_id");
    }

    public function itemVariant()
    {
        return $this->belongsTo(ItemVariant::class, 'item_variant_id', 'id');
    }

    public function itemReference()
    {
        return $this->belongsTo(ItemReference::class, 'item_reference_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }


    public function getDisplayPriceAttribute()
    {
        return $this->itemVariant->reference->item->display_price;
    }
}
