/******************************************************************************
 * Copyright (c)  2024 PingCAP                                                *
 * Licensed under the Apache License, Version 2.0 (the "License");            *
 * you may not use this file except in compliance with the License.           *
 * You may obtain a copy of the License at                                    *
 *                                                                            *
 * http://www.apache.org/licenses/LICENSE-2.0                                 *
 *                                                                            *
 * Unless required by applicable law or agreed to in writing, software        *
 * distributed under the License is distributed on an "AS IS" BASIS,          *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
 * See the License for the specific language governing permissions and        *
 * limitations under the License.                                             *
 ******************************************************************************/

package message

const (
	// DefaultIntegrationTaskFrequency is the default frequency for integration tasks
	DefaultIntegrationTaskFrequency = "10m"
	// DefaultIntegrationTaskDataFormat is the default data format for integration tasks
	DefaultIntegrationTaskDataFormat = "gzip-csv"
)

// CreateIntegrationTaskReq represents the request to create an integration task
type CreateIntegrationTaskReq struct {
	DisplayName     string `json:"displayName" binding:"required"`
	DataType        string `json:"dataType" binding:"required" validate:"oneof=slowquery rawlog sqlstmt"`
	AccessPrincipal string `json:"accessPrincipal"`
	Frequency       string `json:"frequency,omitempty" default:"10m"`
	DataFormat      string `json:"dataFormat,omitempty" default:"gzip-csv"`
	// DataPrefix is used for object storage destination, representing the prefix of the object key where the data will be stored.
	// For example, if DataPrefix is "logs/", the actual object key might be "logs/cluster1/slowquery-20240101.csv.gz".
	DataPrefix       string   `json:"dataPrefix,omitempty"`
	JobType          string   `json:"jobType,omitempty" default:"Once"`
	StartTime        string   `json:"startTime,omitempty"`
	EndTime          string   `json:"endTime,omitempty"`
	RawLogComponents []string `json:"rawLogComponents,omitempty"`
	ClusterID        string   `swaggerignore:"true" json:"clusterID"`
	TenantID         string   `swaggerignore:"true" json:"tenantID"`
	BizType          string   `swaggerignore:"true" json:"bizType"`
	UserID           string   `json:"userId,omitempty" swaggerignore:"true"`
}

// CreateIntegrationTaskResp represents the response after creating an integration task
type CreateIntegrationTaskResp struct {
	ID               string          `json:"id"`
	Name             string          `json:"name"`
	DisplayName      string          `json:"displayName"`
	DataType         string          `json:"dataType"`
	ClusterID        string          `json:"clusterID"`
	AccessPrincipal  string          `json:"accessPrincipal"`
	Frequency        string          `json:"frequency,omitempty"`
	DataFormat       string          `json:"dataFormat,omitempty"`
	DataPrefix       string          `json:"dataPrefix,omitempty"`
	JobType          string          `json:"jobType,omitempty"`
	StartTime        string          `json:"startTime,omitempty"`
	EndTime          string          `json:"endTime,omitempty"`
	RawLogComponents []string        `json:"rawLogComponents,omitempty"`
	DestinationInfo  DestinationInfo `json:"destinationInfo,omitempty"`
	CreateTime       string          `json:"createTime"`
}

// DetailIntegrationTaskReq represents the request to get integration task details
type DetailIntegrationTaskReq struct {
	ID        string `json:"id" binding:"required"`
	ClusterID string `swaggerignore:"true"`
}

// DetailIntegrationTaskResp represents the response with integration task details
type DetailIntegrationTaskResp struct {
	ID               string          `json:"id"`
	Name             string          `json:"name"`
	DisplayName      string          `json:"displayName"`
	DataType         string          `json:"dataType"`
	ClusterID        string          `json:"clusterID"`
	AccessPrincipal  string          `json:"accessPrincipal"`
	Frequency        string          `json:"frequency,omitempty"`
	DataFormat       string          `json:"dataFormat,omitempty"`
	DataPrefix       string          `json:"dataPrefix,omitempty"`
	JobType          string          `json:"jobType,omitempty"`
	StartTime        string          `json:"startTime,omitempty"`
	EndTime          string          `json:"endTime,omitempty"`
	RawLogComponents []string        `json:"rawLogComponents,omitempty"`
	Phase            string          `json:"phase"`
	DestinationInfo  DestinationInfo `json:"destinationInfo,omitempty"`
	CreateTime       string          `json:"createTime"`
}

// DestinationInfo represents destination information for the integration task
type DestinationInfo struct {
	AccessPoint   string `json:"accessPoint,omitempty"`
	AssumeRoleARN string `json:"assumeRoleARN,omitempty"`
}

// DeleteIntegrationTaskReq represents the request to delete an integration task
type DeleteIntegrationTaskReq struct {
	ID        string `json:"id" binding:"required"`
	ClusterID string `swaggerignore:"true" json:"clusterID"`
}

// DeleteIntegrationTaskResp represents the response after deleting an integration task
type DeleteIntegrationTaskResp struct {
	ID      string `json:"id"`
	Message string `json:"message"`
}

// QueryIntegrationTasksReq represents the request to query integration tasks
type QueryIntegrationTasksReq struct {
	DataType  *string `form:"dataType"`
	PageToken string  `form:"pageToken"`
	PageSize  int     `form:"pageSize"`
	TenantID  string  `swaggerignore:"true"`
	ClusterID string  `swaggerignore:"true"`
	BizType   string  `swaggerignore:"true"`
	UserID    string  `swaggerignore:"true"`
}

// QueryIntegrationTasksResp represents the response with integration tasks list
type QueryIntegrationTasksResp struct {
	Pipelines      []IntegrationTaskSummary `json:"pipelines"`
	OAPIPagination `json:",inline"`
}

// IntegrationTaskSummary represents a summary of an integration task
type IntegrationTaskSummary struct {
	ID               string          `json:"id"`
	DataType         string          `json:"dataType"`
	AccessPrincipal  string          `json:"accessPrincipal"`
	Frequency        string          `json:"frequency,omitempty"`
	DataFormat       string          `json:"dataFormat,omitempty"`
	DataPrefix       string          `json:"dataPrefix,omitempty"`
	JobType          string          `json:"jobType,omitempty"`
	StartTime        string          `json:"startTime,omitempty"`
	EndTime          string          `json:"endTime,omitempty"`
	RawLogComponents []string        `json:"rawLogComponents,omitempty"`
	DestinationInfo  DestinationInfo `json:"destinationInfo,omitempty"`
	Phase            string          `json:"phase"`
	CreateTime       string          `json:"createTime"`
}

// UpdateIntegrationTaskReq represents the request to update an integration task
type UpdateIntegrationTaskReq struct {
	ID         string  `json:"id" binding:"required"`
	Frequency  *string `json:"frequency,omitempty"`
	DataFormat *string `json:"dataFormat,omitempty"`
}

// UpdateIntegrationTaskResp represents the response after updating an integration task
type UpdateIntegrationTaskResp struct {
	DetailIntegrationTaskResp
}
