<?php

namespace App\Models;

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

class WorkflowTask extends Model
{
    use HasFactory;

    protected $fillable = [
        'instance_id',
        'document_id',
        'workflow_id',
        'assigned_role',
        'assigned_user',
        'status',
        'current_stage',
        'transition_id',
        'step_id', // Ensure step_id is mass assignable
    ];

    public function instance()
    {
        return $this->belongsTo(WorkflowInstance::class, 'instance_id');
    }

    public function document()
    {
        return $this->belongsTo(Document::class, 'document_id');
    }

    public function assignedRole()
    {
        return $this->belongsTo(\Spatie\Permission\Models\Role::class, 'assigned_role');
    }

    public function assignedUser()
    {
        return $this->belongsTo(User::class, 'assigned_user');
    }

    public function workflow()
    {
        return $this->belongsTo(Workflow::class, 'workflow_id');
    }

        public function transition()
    {
        return $this->belongsTo(WorkflowTransition::class, 'transition_id');
    }

}
