<?php

namespace Modules\Subscription\Repositories;

use Modules\Subscription\Interfaces\SubscriptionRepositoryInterface;
use Modules\Subscription\Models\Subscription;

class SubscriptionRepository implements SubscriptionRepositoryInterface
{
    public function get(array $request)
    {
        return Subscription::query();
    }

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

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

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

    public function create(array $request): Subscription
    {
        $subscription = Subscription::create($request);
        return $subscription;
    }

    public function update(array $request, ?Subscription $subscription): Subscription
    {
        $subscription->update($request);

        return $subscription;
    }

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

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

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

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