<?php

namespace App\Repositories;

use App\Models\Backup;
use Illuminate\Database\Eloquent\Builder;

class BackupRepository
{
    protected Backup $model;

    public function __construct(Backup $model)
    {
        $this->model = $model;
    }

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

    public function paginate(int $perPage = 25)
    {
        return $this->query()->orderBy('created_at', 'desc')->paginate($perPage);
    }

    public function create(array $data): Backup
    {
        return Backup::create($data);
    }

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

    public function update(int $id, array $data): ?Backup
    {
        $b = $this->find($id);
        if (! $b) {
            return null;
        }
        $b->update($data);

        return $b;
    }
}
