<?php

namespace App\Repositories\Shop;

use App\Models\Shop\Basket;
use App\Traits\Model\Basic;
use Darryldecode\Cart\CartCollection;

class BasketStores
{
    use Basic;

    public static function has($key)
    {
        return Basket::find($key);
    }

    public static function get($key)
    {
        return self::has($key) ? new CartCollection(Basket::find($key)->cart_data) : [];
    }

    public static function put($key, $value)
    {
        if ($row = Basket::find($key)) {
            $row->cart_data = $value;
            $row->save();
        } else {
            Basket::create([
                'id' => $key,
                'cart_data' => $value,
            ]);
        }
    }

    public static function getModel()
    {
        return Basket::query();
    }
}
