<?php

namespace App\Domain\Experiment\Models;

use App\Domain\Shared\Traits\BelongsToTeam;
use App\Models\User;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ExperimentStateTransition extends Model
{
    use BelongsToTeam, HasUuids;

    public $timestamps = false;

    protected $fillable = [
        'team_id',
        'experiment_id',
        'from_state',
        'to_state',
        'reason',
        'actor_id',
        'metadata',
        'judge_verdict',
        'created_at',
        'error_metadata',
    ];

    protected function casts(): array
    {
        return [
            'metadata' => 'array',
            'judge_verdict' => 'array',
            'created_at' => 'datetime',
            'error_metadata' => 'array',
        ];
    }

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

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