<?php

namespace App\Models;

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

class DealerProvisioningRun extends Model
{
    use HasFactory;

    protected $fillable = [
        'dealer_id',
        'triggered_by_user_id',
        'run_type',
        'status',
        'started_at',
        'finished_at',
        'summary_json',
        'error_message',
    ];

    protected $casts = [
        'summary_json' => 'array',
        'started_at' => 'datetime',
        'finished_at' => 'datetime',
    ];

    public function dealer(): BelongsTo
    {
        return $this->belongsTo(Dealer::class);
    }

    public function triggeredByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'triggered_by_user_id');
    }
}

