// Package dto add by blacknc <blacknc@163.com> at 2023/03/20 17:04:07
package dto

const (
	// bus event type
	BusEventLinkCluster   = "DataAppBindCluster"
	BusEventCluster       = "ClusterEvent"
	BusEventDataapp       = "DataappEvent"
	BusEventDataappDeploy = "DataappDeployEvent"
	BusEventEndpoint      = "EndpointEvent"

	//bus action type
	// cluster
	ClusterActionDel            = "ClusterDeleted"
	ClusterActionNormal         = "ClusterNormal"
	ClusterActionProjectChanged = "ClusterProjectChanged"

	// dataapp
	DataappActionCreate             = "DataappCreate"
	DataappActionDelete             = "DataappDelete"
	DataappActionDeploy             = "DataappDeploy"
	DataappActionUpdateLogResSwitch = "DataappActionUpdateLogResSwitch"
	// endpoint
	EndpointActionSave     = "EndpointSave"
	EndpointActionDelete   = "EndpointDelete"
	EndpointActionDeploy   = "EndpointDeploy"
	EndpointActionUndeploy = "EndpointUndeploy"
)

type LinkClusterEvent struct {
	OrgID     uint64 `json:"org_id"`
	ProjectID uint64 `json:"project_id"`
	ClusterID uint64 `json:"cluster_id"`
	DataappID uint64 `json:"dataapp_id"`
	Operator  string `json:"operator"`
	Optime    int64  `json:"optime"`
	EventType string `json:"event_type"`
}

type DataAppBindClusterEvent struct {
	EventType  DataAppBindClusterAction `json:"event_type"`
	DataAppID  uint64                   `json:"dataapp_id"`
	ApiKeyID   uint64                   `json:"api_key_id"`
	ClusterIDs []uint64                 `json:"cluster_ids"`
	Operator   string                   `json:"operator"`
	Optime     int64                    `json:"optime"`
}

type DataAppBindClusterAction string

const (
	DataAppBindClusterActionAddApiKey  DataAppBindClusterAction = "add_api_key"
	DataAppBindClusterActionDelApiKey  DataAppBindClusterAction = "delete_api_key"
	DataAppBindClusterActionAddCluster DataAppBindClusterAction = "add_cluster"
	DataAppBindClusterActionDelCluster DataAppBindClusterAction = "delete_cluster"
)

type ClusterEvent struct {
	TenantID         uint64                 `json:"tenant_id,string"`
	ProjectID        uint64                 `json:"project_id,string"`
	ClusterID        uint64                 `json:"cluster_id,string"`
	OperatorID       uint64                 `json:"operator_id,string"`
	IsDevTier        bool                   `json:"is_dev_tier"`
	Status           string                 `json:"status"` // refer to idl/core/core/core.proto:ClusterStatus
	EventType        string                 `json:"event_type"`
	EventCreatedAtMs int64                  `json:"event_created_at_ms,string"` // unix timestamp in milliseconds t.UnixMilli()
	ExtraInfo        map[string]interface{} `json:"extra_info,omitempty"`
}

type BaseEvent struct {
	ActionType string `json:"action_type"`
	Operator   string `json:"operator"`
	Optime     int64  `json:"optime"`
}

type DataappDeployEvent struct {
	BaseEvent
	DataappID       uint64 `json:"dataapp_id"`
	EndpointRequest struct {
		AddIDs      []uint64 `json:"add_ids"`
		ModifyIDs   []uint64 `json:"modify_ids"`
		DeleteIDs   []uint64 `json:"delete_ids"`
		DeployIDs   []uint64 `json:"deploy_ids"`
		UndeployIDs []uint64 `json:"undeploy_ids"`
	} `json:"endpoint_request"`
	ClusterRequest struct {
		AddIDs    []uint64 `json:"add_ids"`
		DeleteIDs []uint64 `json:"delete_ids"`
	} `json:"cluster_request"`
}

type DataappEvent struct {
	BaseEvent
	DataappID uint64 `json:"dataapp_id"`
}

type EndpointEvent struct {
	BaseEvent
	EndpointID  uint64   `json:"endpoint_id"`
	EndpointIDs []uint64 `json:"endpoint_ids"`
}
