//go:generate ${GOBIN}/dummygen -d=api_dummy.go -package=userbehavior ${GO_MODULE}/pkg/service/userbehavior UserBehaviorServiceAPI
package userbehavior

import (
	"context"

	"github.com/tidbcloud/devops/entity"
	ubent "github.com/tidbcloud/devops/entity/userbehavior"
	"github.com/tidbcloud/devops/pkg/service"
)

type UserBehaviorServiceAPI interface {
	ListSubscriptions(ctx context.Context, param ListSubscriptionParam) ([]*ubent.Subscription, int64, error)
	GetSubscription(ctx context.Context, id uint64) (*ubent.Subscription, error)
	CreateSubscription(ctx context.Context, param CreateSubscriptionParam) (*uint64, error)
	DeleteSubscription(ctx context.Context, id uint64) error
	EditSubscription(ctx context.Context, id uint64, param EditSubscriptionParam) error
	ChangeSubscriptionAvailability(ctx context.Context, available bool) error
	SendMockEventToSubscription(ctx context.Context, id uint64) error
	SuppressGTMEmail(ctx context.Context, param SuppressGTMEmailParam) (*SuppressGTMEmailResult, error)
	// May move to other places in the future
	GetLarkChatOptions(ctx context.Context) ([]*entity.LarkChatSimplified, error)
	AddExternalLarkChat(ctx context.Context, param AddExternalLarkChatParam) error
}

const (
	GTMCampaignQualifiedSignupFollowup = "qualified-signup-followup"

	GTMEmailSuppressStatusCancelled             = "cancelled"
	GTMEmailSuppressStatusAlreadySentOrSending  = "already_sent_or_sending"
	GTMEmailSuppressStatusNotFoundButSuppressed = "not_found_but_suppressed"
)

type UserBehaviorService interface {
	UserBehaviorServiceAPI

	service.RunnableService
}

type ListSubscriptionParam struct {
	Page    int
	PerPage int
	Creator *string
	EventTp *ubent.UBEventTp
}

type CreateSubscriptionParam struct {
	Name               string                       `json:"name"`
	SubscribeType      ubent.SubscribeTp            `json:"subscribe_type"`
	LarkChats          []*entity.LarkChatSimplified `json:"lark_chats"`
	EventType          ubent.UBEventTp              `json:"event_type"`
	Template           string                       `json:"template"`
	Selector           ubent.SelectorTp             `json:"selector"`
	OnlyPaidTenant     bool                         `json:"only_paid_tenant"`
	OnlyExternalTenant bool                         `json:"only_external_tenant"`
	Creator            string                       `json:"creator"` // Creator email
	DetailLink         *string                      `json:"detail_link"`
}

type EditSubscriptionParam struct {
	Name           string                       `json:"name"`
	SubscribeType  ubent.SubscribeTp            `json:"subscribe_type"`
	LarkChats      []*entity.LarkChatSimplified `json:"lark_chats"`
	EventType      ubent.UBEventTp              `json:"event_type"`
	Template       string                       `json:"template"`
	Selector       ubent.SelectorTp             `json:"selector"`
	OnlyPaidTenant bool                         `json:"only_paid_tenant"`
}

type AddExternalLarkChatParam struct {
	Name      string  `json:"name"`
	ChatURL   string  `json:"chat_url"`
	AvatarURL *string `json:"avatar_url"`
}

type SuppressGTMEmailParam struct {
	TenantID     uint64
	CampaignName string
	Source       string
	Reason       string
}

type SuppressGTMEmailResult struct {
	Status         string
	CancelledCount int64
}
