package dingtalk

import (
	"ai_scheduler/internal/data/constants"
	"time"

	dingtalkim_1_0 "github.com/alibabacloud-go/dingtalk/im_1_0"
)

type DingTalkAuthIRes struct {
	AccessToken string `json:"accessToken"`
	ExpireIn    int64  `json:"expireIn"`
}

type UserInfoRes struct {
	Errcode   int               `json:"errcode"`
	Errmsg    string            `json:"errmsg"`
	Result    UserInfoResResult `json:"result"`
	RequestId string            `json:"request_id"`
}

type UserInfoResResult struct {
	Active        bool      `json:"active"`
	Admin         bool      `json:"admin"`
	Avatar        string    `json:"avatar"`
	Boss          bool      `json:"boss"`
	CreateTime    time.Time `json:"create_time"`
	DeptIdList    []int     `json:"dept_id_list"`
	DeptOrderList []struct {
		DeptId int   `json:"dept_id"`
		Order  int64 `json:"order"`
	} `json:"dept_order_list"`
	ExclusiveAccount bool   `json:"exclusive_account"`
	HideMobile       bool   `json:"hide_mobile"`
	HiredDate        int64  `json:"hired_date"`
	JobNumber        string `json:"job_number"`
	LeaderInDept     []struct {
		DeptId int  `json:"dept_id"`
		Leader bool `json:"leader"`
	} `json:"leader_in_dept"`
	ManagerUserid string `json:"manager_userid"`
	Name          string `json:"name"`
	RealAuthed    bool   `json:"real_authed"`
	RoleList      []struct {
		GroupName string `json:"group_name"`
		Id        int    `json:"id"`
		Name      string `json:"name"`
	} `json:"role_list"`
	Senior  bool   `json:"senior"`
	Title   string `json:"title"`
	Unionid string `json:"unionid"`
	Userid  string `json:"userid"`
}

type DeptRes struct {
	Errcode       int           `json:"errcode"`
	Errmsg        string        `json:"errmsg"`
	DeptResResult DeptResResult `json:"result"`
	RequestId     string        `json:"request_id"`
}

type DeptResResult struct {
	DeptPermits           []int         `json:"dept_permits"`
	OuterPermitUsers      []string      `json:"outer_permit_users"`
	DeptManagerUseridList []string      `json:"dept_manager_userid_list"`
	OrgDeptOwner          string        `json:"org_dept_owner"`
	OuterDept             bool          `json:"outer_dept"`
	DeptGroupChatId       string        `json:"dept_group_chat_id"`
	GroupContainSubDept   bool          `json:"group_contain_sub_dept"`
	AutoAddUser           bool          `json:"auto_add_user"`
	HideDept              bool          `json:"hide_dept"`
	Name                  string        `json:"name"`
	OuterPermitDepts      []int         `json:"outer_permit_depts"`
	UserPermits           []interface{} `json:"user_permits"`
	DeptId                int           `json:"dept_id"`
	CreateDeptGroup       bool          `json:"create_dept_group"`
	Order                 int           `json:"order"`
	Code                  string        `json:"code"`
	UnionDeptExt          struct {
		CorpId string `json:"corp_id"`
		DeptId int    `json:"dept_id"`
	} `json:"union_dept_ext"`
}

type AuthInfo struct {
	ClientId     string        `json:"clientId"`
	ClientSecret string        `json:"clientSecret"`
	AccessToken  string        `json:"accessToken"`
	Expire       time.Duration `json:"expireIn"`
}

type CardSend struct {
	RobotCode        string
	ConversationType constants.ConversationType
	ConversationId   string
	Template         constants.CardTemp
	SenderStaffId    string
	Title            string
	ContentSlice     []string
	ContentChannel   chan string
	UpdateInterval   time.Duration // 控制通道更新的频率
}

type UpdateCardRequest struct {
	Template       string
	Content        string
	Client         *dingtalkim_1_0.Client
	RobotCode      string
	CardInstanceId string
}
