<?php

namespace App\Repositories;

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

class ZoneRepository
{
    public function __construct(protected Zone $model) {}

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

    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): ?Zone
    {
        return $this->query()->find($id);
    }

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

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

    public function delete(Zone $zone): bool
    {
        return $zone->delete();
    }
}
