<?php

namespace Modules\Refund\Repositories;

use Illuminate\Http\Request;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Refund\Interfaces\RefundRepositoryInterface;
use Modules\Refund\Models\Refund;
use Modules\Refund\Models\RefundDescription;
use Modules\Refund\Models\RefundStatus;

class RefundRepository implements RefundRepositoryInterface
{
    public function get(array $request)
    {
        $builder = Refund::with(['address','order','card','reason','statuses'])->orderBy('id', 'DESC');
        return $builder;
    }

    public function getItem(int $id)
    {
        return Refund::with(['address','order','card','reason','statuses'])->find($id);
    }

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


    public function checkUUIDExists($uuid)
    {
        return Refund::where('uuid',$uuid)->first();
    }

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

    public function create(array $request): Refund
    {
        $refund = Refund::create($request);
        return $refund;
    }
    public function createStatus(array $request)
    {
        RefundStatus::create($request);
    }

    public function update(array $request, ?Refund $refund): Refund
    {
        $refund->update($request);

        return $refund;
    }

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

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

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

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