<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ArchiveRun extends Model
{
    use HasFactory;

    protected $fillable = [
        'archive_setting_id',
        'user_id',
        'status',
        'counts',
        'context',
        'started_at',
        'finished_at',
        'duration_ms',
        'message',
    ];

    protected function casts(): array
    {
        return [
            'counts' => 'array',
            'context' => 'array',
            'started_at' => 'datetime',
            'finished_at' => 'datetime',
        ];
    }

    public function setting()
    {
        return $this->belongsTo(ArchiveSetting::class, 'archive_setting_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
