<?php

namespace App\Repositories;

use App\Models\EmailTemplate;
use Illuminate\Pagination\LengthAwarePaginator;

class EmailTemplateRepository
{
    public function __construct(protected EmailTemplate $model) {}

    public function query()
    {
        return $this->model->newQuery();
    }

    public function getForDataTable()
    {
        return $this->query();
    }

    public function paginate(int $perPage = 25): LengthAwarePaginator
    {
        return $this->query()->latest('id')->paginate($perPage);
    }

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

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

    public function update(EmailTemplate $template, array $data): bool
    {
        return $template->update($data);
    }

    public function delete(EmailTemplate $template): bool
    {
        return $template->delete();
    }
}
