<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * 医学计算器问题模型
 * Class MedicalQuestion
 * @package app\model
 */
class MedicalQuestion extends Model
{
    /**
     * 数据表名称
     * @var string
     */
    protected $name = 'medical_questions';

    /**
     * 自动写入时间戳
     * @var bool
     */
    protected $autoWriteTimestamp = false;

    /**
     * 设置字段信息
     * @var array
     */
    protected $schema = [
        'id'                    => 'int',
        'medical_calculator_id' => 'int',
        'question'             => 'string',
        'variable_name'        => 'string',
        'type'                 => 'string',
        'score'                => 'float',
    ];

    /**
     * 允许批量赋值的字段
     * @var array
     */
    protected $allowField = [
        'medical_calculator_id',
        'question',
        'variable_name',
        'type',
        'score'
    ];

    /**
     * 获取选项列表
     */
    public function options()
    {
        return $this->hasMany(MedicalOption::class, 'medical_question_id', 'id')
            ->order('id', 'asc');
    }

    /**
     * 获取所属计算器
     */
    public function calculator()
    {
        return $this->belongsTo(MedicalCalculator::class, 'medical_calculator_id', 'id');
    }
}