<?php

namespace App\Models;

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

class JobSourceSyncLog extends Model
{
    public const STATUS_SUCCESS = 'success';

    public const STATUS_FAILED = 'failed';

    protected $fillable = [
        'job_source_id',
        'status',
        'jobs_imported',
        'jobs_expired',
        'duration_ms',
        'message',
        'started_at',
        'finished_at',
    ];

    /**
     * @return BelongsTo<JobSource, $this>
     */
    public function source(): BelongsTo
    {
        return $this->belongsTo(JobSource::class, 'job_source_id');
    }

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'jobs_imported' => 'integer',
            'jobs_expired' => 'integer',
            'duration_ms' => 'integer',
            'started_at' => 'datetime',
            'finished_at' => 'datetime',
        ];
    }
}
