package larkcli

import (
	"github.com/tidbcloud/devops/pkg/infra/clients/larkcli/chat"
	"github.com/tidbcloud/devops/pkg/infra/clients/larkcli/contact"
	"github.com/tidbcloud/devops/pkg/infra/clients/larkcli/document"
	"github.com/tidbcloud/devops/pkg/infra/clients/larkcli/im"
	"github.com/tidbcloud/devops/pkg/infra/clients/larkcli/notify"
	"github.com/tidbcloud/devops/pkg/infra/clients/larkcli/sheets"
	"github.com/tidbcloud/devops/pkg/infra/clients/larkcli/task"
	"github.com/tidbcloud/devops/pkg/infra/config"

	lark "github.com/larksuite/oapi-sdk-go/v3"
)

type LarkClient struct {
	Raw      *lark.Client
	Notify   notify.Notification
	Contact  contact.Contact
	Task     task.Task
	Chat     chat.Chat
	Document document.Document
	IM       im.IM
	Sheets   sheets.Sheets
}

func New(conf *config.RootConfig) *LarkClient {
	return NewWithApp(conf.Clients.Lark.Global.AppCode, conf.Clients.Lark.Global.AppSecret, conf.Clients.Lark.Global.LarkBaseURL)
}

func NewWithApp(appCode string, appSecret string, larkBaseURL string) *LarkClient {
	raw := lark.NewClient(appCode, appSecret)
	return &LarkClient{
		Raw:      raw,
		Notify:   notify.New(raw, notify.MsgCardSet),
		Contact:  contact.New(raw),
		Task:     task.New(raw),
		Chat:     chat.New(raw),
		Document: document.New(raw, larkBaseURL),
		IM:       im.New(raw),
		Sheets:   sheets.New(raw),
	}
}
