package domain

import (
	"encoding/json"
	"openapi/pkg/infrastructure/log"
)

/*PushInfo 推送信息*/
type PushInfoOriginalRequest struct {
	Type         int      `json:"msgType"`
	ClientIdList []string `json:"clientId"`
	AppKey       string   `json:"appKey" valid:"Required"`
	Secret       string   `json:"secret" valid:"Required"`
	AppId        string   `json:"appId" valid:"Required"`

	Title   string                 `json:"title" valid:"Required"`
	Content string                 `json:"content" valid:"Required"`
	Ext     map[string]interface{} `json:"ext"` //key->transData:透传数据
}
type PushInfoResponse struct {
	ExtData map[string]interface{} `json:"-"`
}

/*PushInfo 推送信息*/
type PushInfoRequest struct {
	Type       int     `json:"msgType"`
	Receivers  []int64 `json:"receivers"` //接受用户id列表
	ProjectKey string  `json:"project"`   //ability

	Title   string                 `json:"title" valid:"Required"`
	Content string                 `json:"content" valid:"Required"`
	Ext     map[string]interface{} `json:"ext"` //key->transData:透传数据

	ActualReceivers []int64 `json:"-"` //实际发送的人员id列表
}

/*UpdateDevice 更新设备*/
type UpdateDeviceRequest struct {
	ProjectKey  string `json:"projectKey"`             //项目主编号
	Muid        int64  `json:"muid" valid:"Required;"` //企业平台中的用户 UID
	ClientId    string `json:"clientId" valid:"Required"`
	DeviceToken string `json:"deviceToken"`
	Phone       string `json:"phone"`
}
type UpdateDeviceResponse struct {
}

//设备信息
type Device struct {
	Uid         int64
	ClientId    string
	DeviceToken string
	IsActive    int
}

//应用信息
type AppInfo struct {
	Id              int
	AppKey          string
	AppMasterSecret string
	AppId           string
	ProjectId       int //项目编号
	ExtInfo         string
}

type ExtInfo struct {
	Intent string `json:"intent"`
	Sound  string `json:"sound,omitempty"`
}

func (t *AppInfo) GetExtInfo() (*ExtInfo, bool) {
	extInfo := &ExtInfo{}
	if len(t.ExtInfo) == 0 {
		return nil, false
	}
	if err := json.Unmarshal([]byte(t.ExtInfo), extInfo); err != nil {
		log.Error(err.Error())
		return nil, false
	}
	return extInfo, true
}