<?php

namespace Modules\ChipOrder\Repositories;


use Modules\ChipOrder\Interfaces\ChipOrderRepositoryInterface;
use Modules\ChipOrder\Models\ChipOrder;
use Modules\ChipOrder\Models\ChipOrderProduct;

class ChipOrderRepository implements ChipOrderRepositoryInterface
{
    public function get(array $request)
    {
        return ChipOrder::query();
    }


    public function getItem(int $id)
    {
        return ChipOrder::find($id);
    }

    public function checkItem(int $id)
    {
        return ChipOrder::find($id);
    }

    public function getItemTrashed(int $id)
    {
        $chipOrder = ChipOrder::onlyTrashed()->find($id);
        return $chipOrder;
    }

    public function create(array $request): ChipOrder
    {
        $chipOrder = ChipOrder::create($request);
        return $chipOrder;
    }
    public function createOrderProduct(array $request)
    {
        ChipOrderProduct::create($request);

    }

    public function update(array $request, ?ChipOrder $chipOrder): ChipOrder
    {
        $chipOrder->update($request);

        return $chipOrder;
    }

    /**
     * Remove the specified order from storage.
     * @param ChipOrder $chipOrder
     * @return void
     */
    public function destroy(ChipOrder $chipOrder): void
    {
        $chipOrder->delete();
    }

    /**
     * Remove several cities by IDs.
     *
     * @param array $request
     * @return void
     */
    public function destroyAll(array $ids): void
    {
        ChipOrder::whereIn('id', $ids)->delete();
    }

    /**
     * Restore the specified order from storage.
     *
     * @param ChipOrder $chipOrder
     * @return void
     */
    public function restore(ChipOrder $chipOrder): void
    {
        $chipOrder->restore();
    }

    /**
     * Restore several cities by IDs.
     *
     * @param array $request
     * @return void
     */
    public function restoreAll(array $ids): void
    {
        ChipOrder::whereIn('id', $ids)->onlyTrashed()->restore();
    }
}
