<?php

declare(strict_types=1);

namespace App\Model;



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

/**
 * @property int $inquiry_time_id 主键id
 * @property int $doctor_id 医生id
 * @property int $inquiry_type 接诊类型（1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药）
 * @property int $inquiry_mode 接诊方式（1:图文 2:视频 3:语音 4:电话 5:会员）
 * @property string $inquiry_date 日期(可为空)
 * @property string $start_time 开始时间
 * @property string $end_time 结束时间
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 修改时间
 */
class DoctorInquiryTime extends Model
{
    use Snowflake;

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

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['inquiry_time_id', 'doctor_id', 'inquiry_type', 'inquiry_mode', 'inquiry_date', 'start_time', 'end_time', 'created_at', 'updated_at'];

    protected string $primaryKey = "inquiry_time_id";

    /**
     * 关联医生表
     */
    public function UserDoctor(): HasOne
    {
        return $this->hasOne(UserDoctor::class, 'doctor_id','doctor_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
     * @param array $user_doctor_params
     * @param array $fields
     * @return array|Collection
     */
    public static function getWithDoctorList(array $params = [],array $user_doctor_params = [], array $fields = ['*']): array|Collection
    {
        return self::whereHas('UserDoctor' , function($query) use ($user_doctor_params){
            $query->where($user_doctor_params);
        })
            ->where($params)
            ->get($fields);
    }

    /**
     * 获取数据-多
     * 关联医生表
     * @param array $params
     * @param array $user_doctor_params
     * @param array $user_doctor_not_in_params
     * @param array $fields
     * @return array|Collection
     */
    public static function getWithDoctorNotInList(array $params = [],array $user_doctor_params = [], array $user_doctor_not_in_params = [], array $fields = ['*']): array|Collection
    {
        return self::whereHas('UserDoctor' , function($query) use ($user_doctor_params,$user_doctor_not_in_params){
            $query->where($user_doctor_params)->whereNotIn('doctor_id',$user_doctor_not_in_params);
        })
            ->where($params)
            ->get($fields);
    }

}
