package organization

import (
	"time"

	"github.com/tidbcloud/AgentTeam/internal/store/organization/feishu"
)

type FeishuDirectoryHTTPClientOptions = feishu.FeishuDirectoryHTTPClientOptions
type FeishuDirectoryHTTPClient = feishu.FeishuDirectoryHTTPClient
type FeishuAuthHTTPClientOptions = feishu.FeishuAuthHTTPClientOptions
type FeishuAuthHTTPClient = feishu.FeishuAuthHTTPClient
type FeishuAuthIdentity = feishu.FeishuAuthIdentity
type FeishuDepartment = feishu.FeishuDepartment
type FeishuUser = feishu.FeishuUser
type FeishuUserIdentity = feishu.FeishuUserIdentity
type FeishuDepartmentScope = feishu.FeishuDepartmentScope

const (
	defaultFeishuBaseURL          = feishu.DefaultBaseURL
	feishuAuthRequiredScopeUserID = "contact:user.employee_id:readonly"
	feishuAuthAuthorizePath       = "/open-apis/authen/v1/authorize"
	feishuAuthTokenPath           = "/open-apis/authen/v2/oauth/token"
)

type feishuAuthStatePayload = feishu.AuthStatePayload

func NewFeishuDirectoryHTTPClient(options FeishuDirectoryHTTPClientOptions) (*FeishuDirectoryHTTPClient, error) {
	return feishu.NewFeishuDirectoryHTTPClient(options)
}

func NewFeishuAuthHTTPClient(options FeishuAuthHTTPClientOptions) (*FeishuAuthHTTPClient, error) {
	return feishu.NewFeishuAuthHTTPClient(options)
}

func encodeFeishuAuthState(secret []byte, organizationSlug string, issuedAt time.Time) (string, error) {
	return feishu.EncodeAuthState(secret, organizationSlug, issuedAt)
}

func decodeFeishuAuthState(secret []byte, state string, now time.Time) (feishuAuthStatePayload, error) {
	return feishu.DecodeAuthState(secret, state, now)
}

func feishuAPIErrorMessage(code int, message string) string {
	return feishu.APIErrorMessage(code, message)
}
