<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

final class ReconcileJob extends Model
{
    protected $table = 'reconcile_jobs';

    protected $fillable = [
        'job_no',
        'admin_user_id',
        'admin_site_id',
        'reconcile_type',
        'status',
        'period_start',
        'period_end',
        'summary_json',
        'finished_at',
    ];

    protected function casts(): array
    {
        return [
            'period_start' => 'datetime',
            'period_end' => 'datetime',
            'summary_json' => 'array',
            'finished_at' => 'datetime',
        ];
    }

    /** @return BelongsTo<AdminUser, ReconcileJob> */
    public function adminUser(): BelongsTo
    {
        return $this->belongsTo(AdminUser::class, 'admin_user_id');
    }

    /** @return HasMany<ReconcileItem, ReconcileJob> */
    public function items(): HasMany
    {
        return $this->hasMany(ReconcileItem::class, 'reconcile_job_id');
    }
}
