<?php

namespace Modules\Admin\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Modules\Admin\Repositories\Interfaces\WeeklySpecialRepositoryInterface;
use Modules\WeeklySpecial\Models\WeeklySpecial;

class WeeklySpecialRepository implements WeeklySpecialRepositoryInterface
{
    public function __construct(
        private WeeklySpecial $model
    ) {}

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

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

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

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

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

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

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