package v1

import "encoding/json"

type EventSchemaHeader struct {
	EventId    string `json:"event_id"`
	Token      string `json:"token"`
	CreateTime string `json:"create_time"`
	EventType  string `json:"event_type"`
	TenantKey  string `json:"tenant_key"`
	AppId      string `json:"app_id"`
}

type EventSchemaV2 struct {
	Schema string                 `json:"schema"`
	Header EventSchemaHeader      `json:"header"`
	Event  map[string]interface{} `json:"event"`
}

type EventSchemaV1 struct {
	TS    string                 `json:"ts"`
	UUID  string                 `json:"uuid"`
	Event map[string]interface{} `json:"event"`
}

type LarkCommonRes struct {
	Code int64           `json:"code"`
	Msg  string          `json:"msg"`
	Data json.RawMessage `json:"data"`
}

type LarkTATokenRes struct {
	Code   int64  `json:"code"`
	Msg    string `json:"msg"`
	TAT    string `json:"tenant_access_token"`
	Expire int    `json:"expire"`
}

type LarkCallBack struct {
	Ts    string `json:"ts"`
	Uuid  string `json:"uuid"`
	Token string `json:"token"`
	Type  string `json:"type"`
	Event string `json:"event"`
}

type AuthingTokenRes struct {
	StatusCode int              `json:"statusCode"`
	Message    string           `json:"message"`
	Data       AuthingTokenData `json:"data"`
}

type AuthingTokenData struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

type LarkMsgEventSender struct {
	SenderID struct {
		UnionID string `json:"union_id"`
		UserID  string `json:"user_id"`
		OpenID  string `json:"open_id"`
	} `json:"sender_id"`
	SenderType string `json:"sender_type"`
	TenantKey  string `json:"tenant_key"`
}

type LarkMsgEventMessage struct {
	MessageID   string `json:"message_id"`
	RootID      string `json:"root_id"`
	ParentID    string `json:"parent_id"`
	CreateTime  string `json:"create_time"`
	ChatID      string `json:"chat_id"`
	ChatType    string `json:"chat_type"` // p2p, group, topic_group
	MessageType string `json:"message_type"`
	Content     string `json:"content"`
	Mentions    []struct {
		Key string `json:"key"`
		Id  struct {
			UnionID string `json:"union_id"`
			UserID  string `json:"user_id"`
			OpenID  string `json:"open_id"`
		} `json:"id"`
		Name      string `json:"name"`
		TenantKey string `json:"tenant_key"`
	} `json:"mentions"`
}

type LarkMsgEvent struct {
	Sender  LarkMsgEventSender  `json:"sender"`
	Message LarkMsgEventMessage `json:"message"`
}

type LarkReplyMsg struct {
	Content string `json:"content"`
	MsgType string `json:"msg_type"`
}

type LarkMsg struct {
	Content string `json:"content"`
	MsgType string `json:"msg_type"`
}

type LarkReplyMsgResData struct {
	MessageID      string `json:"message_id"`
	RootID         string `json:"root_id"`
	ParentID       string `json:"parent_id"`
	MessageType    string `json:"message_type"`
	CreateTime     string `json:"create_time"`
	ChatID         string `json:"chat_id"`
	UpperMessageID string `json:"upper_message_id"`
	Body           struct {
		Content string `json:"content"`
	} `json:"body"`
	Mentions []struct {
		Key       string `json:"key"`
		ID        string `json:"id"`
		IdType    string `json:"id_type"`
		Name      string `json:"name"`
		TenantKey string `json:"tenant_key"`
	} `json:"mentions"`
	Sender struct {
		ID         string `json:"id"`
		IdType     string `json:"id_type"`
		SenderType string `json:"sender_type"`
		TenantKey  string `json:"tenant_key"`
	} `json:"sender"`
}

type LarkReaction struct {
	ReactionType struct {
		EmojiType string `json:"emoji_type"`
	} `json:"reaction_type"`
}

type LarkReactionResData struct {
	ReactionId string `json:"reaction_id"`
	Operator   struct {
		OperatorId   string `json:"operator_id"`
		OperatorType string `json:"operator_type"`
	} `json:"operator"`
	ActionTime   string `json:"action_time"`
	ReactionType struct {
		EmojiType string `json:"emoji_type"`
	} `json:"reaction_type"`
}

type LarkSendMsgReqData struct {
	ReceiveId string `json:"receive_id"`
	MsgType   string `json:"msg_type"`
	Content   string `json:"content"`
}

type LarkBotAddedEvent struct {
	ChatId     string `json:"chat_id"`
	OperatorId struct {
		UnionId string `json:"union_id"`
		UserId  string `json:"user_id"`
		OpenId  string `json:"open_id"`
	} `json:"operator_id"`
	External          bool   `json:"external"`
	OperatorTenantKey string `json:"operator_tenant_key"`
	Name              string `json:"name"`
}

type MsgCardBody struct {
	OpenID        string `json:"open_id"`
	UserID        string `json:"user_id"`
	OpenMessageID string `json:"open_message_id"`
	TenantKey     string `json:"tenant_key"`
	Token         string `json:"token"`
	Action        struct {
		Value  map[string]string `json:"value"`
		Tag    string            `json:"tag"`
		Option string            `json:"option"`
	} `json:"action"`
}

type UpdateCardData struct {
	Header   interface{}   `json:"header"`
	Elements []interface{} `json:"elements"`
}

const (
	ChatTypeP2P        = "p2p"
	ChatTypeGroup      = "group"
	ChatTypeTopicGroup = "topic_group"
)

type AnsCard struct {
	Config   AnsCardConfig    `json:"config,omitempty"`
	Elements []AnsCardElement `json:"elements"`
	Header   AnsCardHeader    `json:"header"`
}

type AnsCardConfig struct {
	WideScreenMode bool `json:"wide_screen_mode"`
}

type AnsCardHeader struct {
	Template string            `json:"template"`
	Title    AnsCardTagContent `json:"title"`
}

type AnsCardTagContent struct {
	Content string `json:"content"`
	Tag     string `json:"tag"`
}

type AnsCardElement struct {
	Tag     string            `json:"tag"`
	Content string            `json:"content,omitempty"`
	Actions []AnsCardAction   `json:"actions,omitempty"`
	Text    AnsCardTagContent `json:"text,omitempty"`
}

type AnsCardAction struct {
	Tag   string            `json:"tag"`
	Text  AnsCardTagContent `json:"text"`
	Type  string            `json:"type,omitempty"`
	Value map[string]string `json:"value,omitempty"`
}
