<?php

declare(strict_types=1);

namespace App\Model;



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

/**
 * @property int $prescription_icd_id 主键id
 * @property int $order_prescription_id 订单-处方id
 * @property int $icd_id 疾病id（icd）
 * @property string $icd_name 疾病名称(icd)
 * @property string $icd_code icd编码
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 修改时间
 */
class OrderPrescriptionIcd extends Model
{
    use Snowflake;

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

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['prescription_icd_id', 'order_prescription_id', 'icd_id', 'icd_name', 'icd_code', 'created_at', 'updated_at'];

    protected string $primaryKey = "prescription_icd_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 $params
     * @return bool
     */
    public static function getExists(array $params): bool
    {
        return self::where($params)->exists();
    }

    /**
     * 删除
     * @param array $params
     * @return int|mixed
     */
    public static function deleteOrderPrescriptionIcd(array $params): mixed
    {
        return self::where($params)->delete();
    }

    /**
     * 新增
     * @param array $data
     * @return \Hyperf\Database\Model\Model|OrderPrescriptionIcd
     */
    public static function addOrderPrescriptionIcd(array $data): \Hyperf\Database\Model\Model|OrderPrescriptionIcd
    {
        return self::create($data);
    }
}
