<?php

namespace Modules\Order\Repositories;

use Illuminate\Http\Request;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Order\Interfaces\OrderRepositoryInterface;
use Modules\Order\Models\Order;
use Modules\Order\Models\OrderProduct;

class OrderRepository implements OrderRepositoryInterface
{
    public function get(array $request)
    {
        return Order::query();
    }
    public function getProductsByChildId(int $childId)
    {
        return OrderProduct::whereHas('order', function ($query) use ($childId) {
            $query->where('child_id', $childId);
        })->with('product')->orderBy('id','desc');
    }

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

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

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

    public function create(array $request): Order
    {
        $order = Order::create($request);
        return $order;
    }
    public function createOrderProduct(array $request)
    {
        OrderProduct::create($request);

    }

    public function update(array $request, ?Order $order): Order
    {
        $order->update($request);

        return $order;
    }

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

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

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

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