<?php

namespace App\Repositories;

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

class StaffRepository
{
    public function __construct(protected User $model) {}

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

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

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

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

    public function delete(User $user): bool
    {
        return $user->delete();
    }
}
