<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SopStep extends Model
{
    /**
     * 可批量赋值的属性
     *
     * @var array<string>
     */
    protected $fillable = [
        'sop_template_id',
        'step_number',
        'title',
        'content',
        'sort_order',
        'is_required',
    ];

    /**
     * 属性类型转换
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'is_required' => 'boolean',
        ];
    }

    /**
     * 获取步骤所属的模板
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function template()
    {
        return $this->belongsTo(SopTemplate::class, 'sop_template_id');
    }

    /**
     * 获取步骤的交互任务列表
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function interactiveTasks()
    {
        return $this->hasMany(SopInteractiveTask::class);
    }
}
