<?php

namespace Modules\Admin\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Modules\Admin\Repositories\Interfaces\PaymentMethodRepositoryInterface;
use Modules\Payment\Models\PaymentMethod;

class PaymentMethodRepository implements PaymentMethodRepositoryInterface
{
    public function __construct(
        private PaymentMethod $model
    ) {}

    public function all(): Collection
    {
        return $this->model->all();
    }

    public function find(int $id): ?PaymentMethod
    {
        return $this->model->find($id);
    }

    public function create(array $data): PaymentMethod
    {
        return $this->model->create($data);
    }

    public function update(int $id, array $data): PaymentMethod
    {
        $paymentMethod = $this->find($id);
        $paymentMethod->update($data);
        return $paymentMethod->fresh();
    }

    public function delete(int $id): bool
    {
        return $this->model->destroy($id);
    }

    public function paginate(int $perPage = 10): LengthAwarePaginator
    {
        return $this->model->orderBy('sort_order')->paginate($perPage);
    }

    public function count(): int
    {
        return $this->model->count();
    }
}
