<?php

namespace Modules\Order\Repositories;

use Illuminate\Http\Request;
use Modules\Order\Models\Cart;
use Modules\Order\Interfaces\CartRepositoryInterface;

class CartRepository implements CartRepositoryInterface
{

    public function get($request)
    {
        return Cart::with(['product','option'])->orderBy('id', 'DESC');
    }


    public function getItem(int $id)
    {
        return Cart::with(['product','option'])->find($id);
    }

    public function getCart(array $request)
    {
        return Cart::query()
            ->where('user_status',$request['user_status'])
            ->where('user_id',$request['user_id'])
            ->where('product_id',$request['product_id'])
            ->where('warehouse_id',$request['warehouse_id'])
            ->where('option_id',($request['option_id'] ?? null))
            ->first();
    }

    public function store(array $request): Cart
    {
        $cart = Cart::create($request);
        return $cart;
    }

    public function update(array $request,$cart): Cart
    {
        $cart->update($request);
        return $cart;
    }


    public function destroy(Cart $cart) :array
    {
        $cart->delete();
        return [ ['message'=> __('dashboard.deletedDone')]];
    }

}
