<?php

declare(strict_types=1);

namespace App\Model;



use Hyperf\Database\Model\Collection;
use Hyperf\Snowflake\Concern\Snowflake;

/**
 * @property int $family_personal_id 主键id
 * @property int $family_id 信息表id
 * @property int $patient_id 患者id
 * @property int $is_allergy_history 是否存在过敏史（0:否 1:是）
 * @property string $allergy_history 过敏史描述
 * @property int $is_family_history 是否存在家族病史（0:否 1:是）
 * @property string $family_history 家族病史描述
 * @property int $is_pregnant 是否备孕、妊娠、哺乳期（0:否 1:是）
 * @property string $pregnant 备孕、妊娠、哺乳期描述
 * @property int $is_operation 是否存在手术（0:否 1:是）
 * @property string $operation 手术描述
 * @property int $drink_wine_status 饮酒状态（1:从不 2:偶尔 3:经常 4:每天 5:已戒酒）
 * @property int $smoke_status 吸烟状态（1:从不 2:偶尔 3:经常 4:每天 5:已戒烟）
 * @property int $chemical_compound_status 化合物状态（1:从不 2:偶尔 3:经常 4:每天）
 * @property string $chemical_compound_describe 化合物描述
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 修改时间
 */
class PatientFamilyPersonal extends Model
{
    use Snowflake;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'patient_family_personal';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['family_personal_id', 'family_id', 'patient_id', 'is_allergy_history', 'allergy_history', 'is_family_history', 'family_history', 'is_pregnant', 'pregnant', 'is_operation', 'operation', 'drink_wine_status', 'smoke_status', 'chemical_compound_status', 'chemical_compound_describe', 'created_at', 'updated_at'];

    protected string $primaryKey = "family_personal_id";

    /**
     * 获取数据-单
     * @param array $params
     * @param array $fields
     * @return object|null
     */
    public static function getOne(array $params, array $fields = ['*']): object|null
    {
        return self::where($params)->first($fields);
    }

    /**
     * 获取数据-多
     * @param array $params
     * @param array $fields
     * @return Collection|array
     */
    public static function getList(array $params = [], array $fields = ['*']): Collection|array
    {
        return self::where($params)->get($fields);
    }

    /**
     * 新增
     * @param array $data
     * @return \Hyperf\Database\Model\Model|PatientFamilyPersonal
     */
    public static function addPatientFamilyPersonal(array $data = []): \Hyperf\Database\Model\Model|PatientFamilyPersonal
    {
        return self::create($data);
    }

    /**
     * 修改
     * @param array $params
     * @param array $data
     * @return int
     */
    public static function edit(array $params = [], array $data = []): int
    {
        return self::where($params)->update($data);
    }
}
