package pposRequest

import (
	"PPOSUtils/utils"
	"net/url"
)

func (that *PPOSClient) NewWaterAuth() *WaterAuthRequest {
	return &WaterAuthRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/ticket/water/checkAuth",
		},
	}
}

// WaterAuthRequest 请求参数...
type WaterAuthRequest struct {
	Request
	Type        int64  `json:"type"`         //识别类型 0.刷卡 1.二维码
	Msg         string `json:"msg"`          //识别信息 根据 type 内容不一样, type:0:卡号 1:二维码号
	Mac         string `json:"mac"`          //箱柜屏 mac 地址 水控 mac 地址
	Timestamp   string `json:"timestamp"`    //时间戳,毫秒
	AppKey      string `json:"appKey"`       //应用 key
}

//SetType ...
func (that *WaterAuthRequest) SetType(value int64) *WaterAuthRequest {
	that.Type = value
	return that
}

//SetMsg ...
func (that *WaterAuthRequest) SetMsg(value string) *WaterAuthRequest {
	that.Msg = value
	return that
}

//SetMac ...
func (that *WaterAuthRequest) SetMac(value string) *WaterAuthRequest {
	that.Mac = value
	return that
}

//SetTimestamp ...
func (that *WaterAuthRequest) SetTimestamp(value string) *WaterAuthRequest {
	that.Timestamp = value
	return that
}

//SetAppKey ...
func (that *WaterAuthRequest) SetAppKey(value string) *WaterAuthRequest {
	that.AppKey = value
	return that
}

//Params ...
func (that *WaterAuthRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("type", utils.ToString(that.Type))
	m.Set("msg", that.Msg)
	m.Set("mac", that.Mac)
	m.Set("timestamp", that.Timestamp)
	m.Set("appKey", that.AppKey)
	return m, nil
}

//Do ...
func (that *WaterAuthRequest) Do() (interface{}, error) {
	_responData, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	return _responData, nil
}
