<?php

namespace Modules\Payment\Repositories;

use Modules\Payment\Interfaces\PaymentRepositoryInterface;
use Modules\Payment\Models\Payment;
use Modules\Payment\Models\PaymentDetails;

class PaymentRepository implements PaymentRepositoryInterface
{
    public function get(array $request)
    {
        return Payment::query();
    }

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

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

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

    public function create(array $request): Payment
    {
        
        $payment = Payment::create($request);
        return $payment;
    }

    public function createDetails(array $request): PaymentDetails
    {
        // dd($request);
        $paymentDetails = PaymentDetails::create($request);
        return $paymentDetails;
    }

    public function update(array $request, ?Payment $payment): Payment
    {
        $payment->update($request);

        return $payment;
    }

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

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

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

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