<?php

declare(strict_types=1);

namespace App\Model;



use Hyperf\Database\Model\Relations\HasOne;
use Hyperf\Snowflake\Concern\Snowflake;

/**
 * @property string $inquiry_config_id 主键id
 * @property string $doctor_id 医生id
 * @property int $inquiry_type 接诊类型（1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药）
 * @property int $inquiry_mode 接诊方式（1:图文 2:视频 3:语音 4:电话 5:会员）
 * @property int $work_num_day 每日接诊数量
 * @property string $inquiry_price 接诊价格（专家问诊-公益问诊）
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 修改时间
 */
class DoctorInquiryConfig extends Model
{
    use Snowflake;

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

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['inquiry_config_id', 'doctor_id', 'inquiry_type', 'inquiry_mode', 'work_num_day', 'inquiry_price', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['inquiry_config_id' => 'string', 'doctor_id' => 'string', 'inquiry_type' => 'integer', 'inquiry_mode' => 'integer', 'work_num_day' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    protected string $primaryKey = "inquiry_config_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 object|null
     */
    public static function getInquiryConfigOne(array $params, array $fields = ['*']): object|null
    {
        return self::where($params)->first($fields);
    }

    /**
     * 获取医生接诊配置信息-多条
     * 在线问诊+专家问诊
     * @param array $params
     * @param array $fields
     * @param array $inquiry_type_in_params
     * @return object|null
     */
    public static function getInquiryConfigList(array $params, array $fields = ['*'] , array $inquiry_type_in_params = [1,3]): object|null
    {
        return self::where($params)->whereIn("inquiry_type",$inquiry_type_in_params)->get($fields);
    }

    /**
     * 创建
     * @param array $data
     * @return \Hyperf\Database\Model\Model|DoctorInquiryConfig
     */
    public static function addInquiryConfig(array $data): \Hyperf\Database\Model\Model|DoctorInquiryConfig
    {
        return self::create($data);
    }

    /**
     * 修改医生接诊配置
     * @param array $params
     * @param array $data
     * @return int
     */
    public static function editInquiryConfig(array $params = [], array $data = []): int
    {
        return self::where($params)->update($data);
    }

    /**
     * 获取问诊价格最低的字段
     * @param array $params
     * @return mixed|string|null
     */
    public static function getMinInquiryPriceMinOne(array $params = []): mixed
    {
        return self::where($params)->min('inquiry_price');
    }
}
