package models

import "time"

type Time time.Time

const (
	timeFormart = "2006-01-02 15:04:05"
)

func (t *Time) UnmarshalJSON(data []byte) (err error) {
	now, err := time.ParseInLocation(`"`+timeFormart+`"`, string(data), time.Local)
	*t = Time(now)
	return
}

func (t *Time) Parse(date string) (now time.Time, err error) {
	now, err = time.ParseInLocation(timeFormart, date, time.Local)
	*t = Time(now)
	return
}

func (t Time) MarshalJSON() ([]byte, error) {
	b := make([]byte, 0, len(timeFormart)+2)
	b = append(b, '"')
	b = time.Time(t).AppendFormat(b, timeFormart)
	b = append(b, '"')
	return b, nil
}
func (t Time) String() string {
	return time.Time(t).Format(timeFormart)
}

type WxXcxLoginReq struct {
	Code string `json:"code"`
}

type WxXcxLoginResp struct {
	Token     string `json:"token"`
	OpenId    string `json:"openid"`
	PatientId int64  ` json:"patient_id"`
	UserOrgId int64  ` json:"user_org_id"`
}

type SaveUserInfoReq struct {
	Phone string `json:"phone" description:"手机号码"`
	Email string `json:"email" description:"邮件"`
	//UnionId                 string `json:"union_id" description:"unionid"`
	NickName string `json:"nick_name" description:"昵称"`
	Avatar   string `json:"avatar" description:"头像"`
	//PrivacyProtocolVersions int    `json:"privacy_protocol_versions" description:"隐私政策版本"`

	RealName          string `json:"real_name" description:"真实姓名"`
	IdCard            string `json:"id_card" description:"身份证号"`
	InpatientRegPhone string `json:"inpatient_reg_phone" description:"住院登记手机号"`
}

type UserInfoResp struct {
	Id                      uint64 `json:"id" description:"Primary Key ID"`
	Phone                   string `json:"phone" description:"手机号码"`
	Email                   string `json:"email" description:"邮件"`
	OpenId                  string `json:"open_id" description:"OpenID"`
	UnionId                 string `json:"union_id" description:"unionid"`
	NickName                string `json:"nick_name" description:"昵称"`
	Avatar                  string `json:"avatar" description:"头像"`
	Status                  int    `json:"status" description:"状态(1:有效0:无效)"`
	Source                  string `json:"source" description:"用户来源"`
	PrivacyProtocolVersions int    `json:"privacy_protocol_versions" description:"隐私政策版本"`

	RealName          string `json:"real_name" description:"真实姓名"`
	IdCard            string `json:"id_card" description:"身份证号"`
	InpatientRegPhone string `json:"inpatient_reg_phone" description:"住院登记手机号"`

	PatientId int64 ` json:"patient_id"`
	UserOrgId int64 ` json:"user_org_id"`

	DialysisNo   string `gorm:"column:dialysis_no" json:"dialysis_no" description:" 透析号"`
	HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" description:" 医保号"`

	Ctime Time `json:"ctime" description:"创建时间"`
	Mtime Time `json:"mtime" description:"更新时间 "`
}

type SaveHealthProfileReq struct {
	Gender              int    `json:"gender" description:"性别(0:未知 1:男 2:女)"`
	Height              int    `json:"height" description:"身高"`
	Weight              int    `json:"weight" description:"体重"`
	BloodType           string `json:"blood_type" description:"血型"`
	Birthday            string `json:"birthday" description:"生日 yyyy-MM-dd HH:mm:ss"`
	IllnessState        string `json:"illness_state" description:"病情"`
	RenalFunctionStatus int    `json:"renal_function_status" description:"肾功能情况(0:未透析,1: 血液透析,2:腹膜透析,3:肾脏移植)"`
	Creatinine          int    `json:"creatinine" description:"血肌酐"`
	CreatinineUnit      string `json:"creatinine_unit" description:"肌酐单位(umol/L,mg/dl)"`
	CreatineTime        string `json:"creatine_time" description:"肌酐检测时间 yyyy-MM-dd HH:mm:ss"`
	UrineProtein24hUnit string `json:"urine_protein_24h_unit" description:"24小时尿蛋白单位(g/24h,mg/24h)"`
	UrineProtein24h     int    `json:"urine_protein_24h" description:"24小时尿蛋白"`
	UrineProtein24hTime string `json:"urine_protein_24h_time" description:"24小时尿蛋白检测时间 yyyy-MM-dd HH:mm:ss"`
	UrineProtein        int    `json:"urine_protein" description:"尿蛋白"`
	UrineProteinUnit    string `json:"urine_protein_unit" description:"尿蛋白单位(g,mg)"`
	UrineProteinTime    string `json:"urine_protein_time" description:"尿蛋白检测时间 yyyy-MM-dd HH:mm:ss"`
}

type HealthProfileResp struct {
	Id uint64 `json:"id" description:"Primary Key ID"`
	//UserId              int64     `json:"user_id" description:"用户ID"`
	//RealName            string    `json:"real_name" description:"真实姓名"`
	//IdCard              string    `json:"id_card" description:"身份证号"`
	//InpatientRegPhone   string    `json:"inpatient_reg_phone" description:"住院登记手机号"`
	Gender              int    `json:"gender" description:"性别(0:未知 1:男 2:女)"`
	Height              int    `json:"height" description:"身高"`
	Weight              int    `json:"weight" description:"体重"`
	BloodType           string `json:"blood_type" description:"血型"`
	Birthday            Time   `json:"birthday" description:"生日"`
	IllnessState        string `json:"illness_state" description:"病情"`
	RenalFunctionStatus int    `json:"renal_function_status" description:"肾功能情况(0:未透析,1: 血液透析,2:腹膜透析,3:肾脏移植)"`
	Creatinine          int    `json:"creatinine" description:"血肌酐"`
	CreatinineUnit      string `json:"creatinine_unit" description:"肌酐单位(umol/L,mg/dl)"`
	CreatineTime        Time   `json:"creatine_time" description:"肌酐检测时间"`
	UrineProtein24hUnit string `json:"urine_protein_24h_unit" description:"24小时尿蛋白单位(g/24h,mg/24h)"`
	UrineProtein24h     int    `json:"urine_protein_24h" description:"24小时尿蛋白"`
	UrineProtein24hTime Time   `json:"urine_protein_24h_time" description:"24小时尿蛋白检测时间"`
	UrineProtein        int    `json:"urine_protein" description:"尿蛋白"`
	UrineProteinUnit    string `json:"urine_protein_unit" description:"尿蛋白单位(g,mg)"`
	UrineProteinTime    Time   `json:"urine_protein_time" description:"尿蛋白检测时间"`
	Status              int    `json:"status" description:"状态(1:有效 0:无效 )"`
	Ctime               Time   `json:"ctime" description:"创建时间"`
	Mtime               Time   `json:"mtime" description:"更新时间 "`
}

type DicResp struct {
	Type     string `json:"type"`
	Name     string `json:"name" description:"字典名称"`
	Value    int    `json:"value" description:"字典值"`
	ValueStr string `json:"value_str" description:"字典字符串值"`
}

type OpenEmqMsgReqVO struct {
	UserName   string `json:"username" description:"用户名"`
	Topic      string `json:"topic" description:"主题"`
	PeerHost   string `json:"peerhost" description:"主机"`
	Payload    string `json:"payload" description:"负载"`
	Id         string `json:"id"`
	ProductKey string `json:"productKey" description:"产品key"`
	DeviceName string `json:"deviceName" description:"设备名称"`
	Acc        int    `json:"acc"`
	Type       int    `json:"type"`
	Count      int    `json:"count"`
	DataType   int    `json:"datatype"`
	VerifyCode string `json:"verifycode"`
	Data       string `json:"data"`
	Origin     string `json:"origin"`
	Len        int    `json:"len"`
}

type OpenEmqPayloadReqVO struct {
	ProductKey string `json:"productKey"` // 产品密钥
	DeviceName string `json:"deviceName"` // 设备名称
	Acc        int    `json:"acc"`        // 准确度
	Type       int    `json:"type"`       // 类型
	Count      int    `json:"count"`      // 计数
	Datatype   int    `json:"datatype"`   // 数据类型
	Verifycode int    `json:"verifycode"` // 验证码
	Data       string `json:"data"`       // 数据
	Origin     string `json:"origin"`     // 来源
	Len        int    `json:"len"`        // 长度
}
type CheckItemScopeVO struct {
	Index int    `json:"index"`
	Type  int    `json:"type"`
	Value string `json:"value"`
	Num   string `json:"num"`
}

type AppCheckRecordVO struct {

	// AlertCount is the number of alerts.
	AlertCount int `json:"alert_count" description:"异常数量"`
	// NormalCount is the number of normal items.
	NormalCount int `json:"normal_count" description:"正常数量"`
	// Describe is the description of the record.
	Describe string `json:"describe" description:"描述"`
	// CheckDate is the date when the check was performed.
	CheckDate Time `json:"check_date" description:"检测日期"`
	// CheckRecordID is the ID of the check record.
	CheckRecordId int64 `json:"check_record_id" description:"检测记录id"`
	// UserID is the user ID, defaulting to the user's own ID.
	UserId uint64 `json:"user_id" description:"绑定用户id 默认自己"`
	// AlertGrade is the risk level: 1 for low, 2 for medium, 3 for high.
	//AlertGrade int `json:"alert_grade" description:"风险等级 1 低  2 中 3 高"`
	// View indicates whether the record has been viewed.
	View int `json:"view" description:"是否查看 1 已查看 0 未查看"`
	// Bind indicates whether the user is bound.
	Bind int `json:"bind" description:"0 未绑定用户 1 绑定"`
	// AlertItems is a list of alert items.
	AlertItems []string `json:"alert_items" description:"异常项"`
}

// AppCheckRecordItemDetailsVO 结构体表示检测记录项的详细信息
type AppCheckRecordItemDetailsVO struct {
	NameCn          string             `json:"name_cn" description:"中文名字"`
	NameEn          string             `json:"name_en" description:"英文名字"`
	Unit            string             `json:"unit" description:"单位"`
	Value           string             `json:"value" description:"检测值"`
	ValueIndex      string             `json:"value_index" description:"检测值索引"`
	CheckItemScopes []CheckItemScopeVO `json:"check_item_scopes" description:"检测范围"`
	ReferenceValue  string             `json:"reference_value" description:"参考值"`
	Describe        string             `json:"describe" description:"描述"`
	Alert           bool               `json:"alert" description:"true:异常,false:正常"`
	ID              int                `json:"id" description:"id"`
}

// AppCheckRecordItemVO 结构体表示检测记录项
type AppCheckRecordItemVO struct {
	AlertCount    int                           `json:"alert_count" description:"异常数量"`
	NormalCount   int                           `json:"normal_count" description:"正常数量"`
	Describe      string                        `json:"describe" description:"描述"`
	CheckDate     Time                          `json:"check_date" description:"检测日期"`
	CheckRecordID int64                         `json:"check_record_id" description:"检测记录id"`
	UserID        int64                         `json:"user_id" description:"绑定用户id 默认自己"`
	AlertGrade    int                           `json:"alert_grade" description:"风险等级 1 低  2 中 3 高"`
	Bind          bool                          `json:"bind" description:"false 未绑定用户 true 绑定"`
	Items         []AppCheckRecordItemDetailsVO `json:"items" description:"检测详情"`
	Status        int                           `json:"status" description:"设备绑定状态(扫码查看结果时返回):1 未绑定 2设备为他人绑定 3设备为自己绑定"`
}

type AppCheckRecordItemReportVO struct {
	Unit            string `json:"unit" description:"单位"`
	Value           string `json:"value" description:"检测值"`
	CheckValueIndex int    `json:"check_value_index" description:"检测值下标"`
	Describe        string `json:"describe" description:"描述"`
	ID              int    `json:"id" description:"id"`
	Date            Time   `json:"date" description:"检测时间"`
}

type SyhArticlesVO struct {
	ID          uint   `json:"id" gorm:"column:id; type:int(10) unsigned; primary_key; auto_increment; comment:'自增主键ID'" description:"自增主键ID"`
	Title       string `json:"title" gorm:"column:title; type:varchar(255); not null; comment:'标题'" description:"标题"`
	Summary     string `json:"summary" gorm:"column:summary; type:varchar(255); not null; default:''; comment:'简介'" description:"简介"`
	Content     string `json:"content" gorm:"column:content; type:longtext; not null; comment:'内容'" description:"内容"`
	ArticleType uint8  `json:"article_type" gorm:"column:article_type; type:tinyint(1) unsigned; not null; default:'1'; comment:'1普通2视频'" description:"文章类型"`
	Num         uint   `json:"num" gorm:"column:num; type:int(10) unsigned; default:'0'; comment:'点击次数'" description:"点击次数"`
	Ctime       Time   `json:"ctime" gorm:"column:ctime; type:int(10); not null; default:'0'; comment:'创建时间'" description:"创建时间"`
	NewTime     Time   `json:"new_time" gorm:"column:new_time; type:int(10); not null; default:'0'; comment:'作为新建时间，ctime作为发布修改时间'" description:"新建时间"`
	Img         string `json:"img" gorm:"column:img; type:varchar(255); comment:'图片'" description:"图片"`
	MenuID      uint   `json:"menu_id" gorm:"column:menu_id; type:int(10) unsigned; not null; default:'1'; comment:'辅分类'" description:"辅分类"`
	ClassID     uint   `json:"class_id" gorm:"column:class_id; type:int(10) unsigned; not null; default:'1'; comment:'主分类'" description:"主分类"`
	Author      string `json:"author" gorm:"column:author; type:varchar(20); not null; default:''; comment:'作者'" description:"作者"`
	Tags        string `json:"tags" gorm:"column:tags; type:varchar(50); comment:'标签'" description:"标签"`
	IsDel       uint8  `json:"is_del" gorm:"column:is_del; type:tinyint(1) unsigned; not null; default:'0'; comment:'是否删除'" description:"是否删除"`
	Status      uint8  `json:"status" gorm:"column:status; type:tinyint(1) unsigned; not null; default:'0'; comment:'状态'" description:"状态 0正在审核，1通过，2未通过，3草稿,4通过且大图显示视频"`
	Reason      string `json:"reason" gorm:"column:reason; type:varchar(100); comment:'原因'" description:"原因"`
	FromID      uint   `json:"from_id" gorm:"column:from_id; type:int(10) unsigned; not null; default:'0'; comment:'医生/机构ID'" description:"医生/机构ID"`
	Type        uint8  `json:"type" gorm:"column:type; type:tinyint(1) unsigned; not null; default:'0'; comment:'类型'" description:"类型'0系统1医生2机构"`
	StarNum     uint   `json:"star_num" gorm:"column:star_num; type:int(10) unsigned; not null; default:'0'; comment:'点赞数'" description:"点赞数"`
	CommentNum  uint   `json:"comment_num" gorm:"column:comment_num; type:int(10) unsigned; not null; default:'0'; comment:'评论数'" description:"评论数"`
	TModule     string `json:"t_module" gorm:"column:t_module; type:varchar(50); comment:'模块'" description:"模块"`
	OrgID       uint   `json:"org_id" gorm:"column:org_id; type:int(10); comment:'orgId'" description:"orgId"`
}

// SyhArticlesComment 表示文章评论表的模型
type SyhArticlesCommentVO struct {
	ID         uint   `json:"id" gorm:"column:id; type:int(10) unsigned; primary_key; auto_increment; comment:'自增主键ID'" description:"自增主键ID"`
	ArticleID  uint   `json:"article_id" gorm:"column:article_id; type:int(10) unsigned; not null; comment:'动态ID'" description:"动态ID"`
	UserID     uint   `json:"user_id" gorm:"column:user_id; type:int(10) unsigned; not null; comment:'评论者用户ID'" description:"评论者用户ID"`
	PID        uint   `json:"pid" gorm:"column:pid; type:int(10) unsigned; not null; default:'0'; comment:'父级ID'" description:"父级ID"`
	Content    string `json:"content" gorm:"column:content; type:text; not null; comment:'评论内容'" description:"评论内容"`
	Ctime      Time   `json:"ctime" gorm:"column:ctime; type:int(10) unsigned; not null; comment:'评论时间'" description:"评论时间"`
	Status     uint8  `json:"status" gorm:"column:status; type:tinyint(1) unsigned; not null; default:'1'; comment:'状态'" description:"状态"`
	IsDel      uint8  `json:"is_del" gorm:"column:is_del; type:tinyint(1) unsigned; not null; default:'0'; comment:'1:删除 0：未删除'" description:"是否删除"`
	Type       uint8  `json:"type" gorm:"column:type; type:tinyint(1) unsigned zerofill; not null; default:'1'; comment:'0用户1医生2科室3企业'" description:"类型"`
	TModule    string `json:"t_module" gorm:"column:t_module; type:varchar(50); not null; default:'0'; comment:'模块'" description:"模块"`
	StarNum    uint   `json:"star_num" gorm:"column:star_num; type:int(10) unsigned; not null; default:'0'; comment:'点赞数'" description:"点赞数"`
	CommentNum uint   `json:"comment_num" gorm:"column:comment_num; type:int(10) unsigned; not null; default:'0'; comment:'评论数'" description:"评论数"`
	CommentID  uint   `json:"comment_id" gorm:"column:comment_id; type:int(10) unsigned; not null; default:'0'; comment:'在评论详情页面时用'" description:"评论ID"`
}
