<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;

/**
 * A proposal and its outcome.
 *
 * The agent may only propose. Approval is a separate, human act and is recorded
 * apart from the thing it approved.
 */
#[Fillable([
    'origin', 'action', 'subject_type', 'subject_id', 'params', 'evidence',
    'result', 'state', 'actor', 'reason', 'applied_at',
])]
class Decision extends Model
{
    protected function casts(): array
    {
        return [
            'params' => 'array',
            'evidence' => 'array',
            'result' => 'array',
            'applied_at' => 'datetime',
        ];
    }

    public function isBlocked(): bool
    {
        return $this->state === 'blocked';
    }

    public function wasApplied(): bool
    {
        return $this->state === 'applied';
    }
}
