<?php

namespace App\Models;

/** See CreateBackupRunsTable's migration comment. */
class BackupRunModel extends TenantModel
{
    protected $table            = 'backup_runs';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'object';
    protected $useTimestamps    = true;
    protected $createdField     = 'created_at';
    protected $updatedField     = '';

    protected $allowedFields = [
        'status',
        'local_path',
        'file_size_bytes',
        'emailed',
        'email_error',
        'error_message',
        'triggered_by',
    ];

    public function recent(int $limit = 10): array
    {
        return $this->orderBy('created_at', 'desc')->limit($limit)->findAll();
    }
}
