syntax = "v1"

info (
	title:   "Marketing API"
	desc:    "API for ppanel"
	author:  "Tension"
	email:   "tension@ppanel.com"
	version: "0.0.1"
)

type (
	CreateBatchSendEmailTaskRequest {
		Subject           string `json:"subject"`
		Content           string `json:"content"`
		Scope             int8   `json:"scope"`
		RegisterStartTime int64  `json:"register_start_time,omitempty"`
		RegisterEndTime   int64  `json:"register_end_time,omitempty"`
		Additional        string `json:"additional,omitempty"`
		Scheduled         int64  `json:"scheduled,omitempty"`
		Interval          uint8  `json:"interval,omitempty"`
		Limit             uint64 `json:"limit,omitempty"`
	}
	BatchSendEmailTask {
		Id                int64  `json:"id"`
		Subject           string `json:"subject"`
		Content           string `json:"content"`
		Recipients        string `json:"recipients"`
		Scope             int8   `json:"scope"`
		RegisterStartTime int64  `json:"register_start_time"`
		RegisterEndTime   int64  `json:"register_end_time"`
		Additional        string `json:"additional"`
		Scheduled         int64  `json:"scheduled"`
		Interval          uint8  `json:"interval"`
		Limit             uint64 `json:"limit"`
		Status            uint8  `json:"status"`
		Errors            string `json:"errors"`
		Total             uint64 `json:"total"`
		Current           uint64 `json:"current"`
		CreatedAt         int64  `json:"created_at"`
		UpdatedAt         int64  `json:"updated_at"`
	}
	GetBatchSendEmailTaskListRequest {
		Page   int    `form:"page"`
		Size   int    `form:"size"`
		Scope  *int8  `form:"scope,omitempty"`
		Status *uint8 `form:"status,omitempty"`
	}
	GetBatchSendEmailTaskListResponse {
		Total int64                `json:"total"`
		List  []BatchSendEmailTask `json:"list"`
	}
	StopBatchSendEmailTaskRequest {
		Id int64 `json:"id"`
	}
	GetPreSendEmailCountRequest {
		Scope             int8  `json:"scope"`
		RegisterStartTime int64 `json:"register_start_time,omitempty"`
		RegisterEndTime   int64 `json:"register_end_time,omitempty"`
	}
	GetPreSendEmailCountResponse {
		Count int64 `json:"count"`
	}
	GetBatchSendEmailTaskStatusRequest {
		Id int64 `json:"id"`
	}
	GetBatchSendEmailTaskStatusResponse {
		Status  uint8  `json:"status"`
		Current int64  `json:"current"`
		Total   int64  `json:"total"`
		Errors  string `json:"errors"`
	}
	CreateQuotaTaskRequest {
		Subscribers  []int64 `json:"subscribers"`
		IsActive     *bool   `json:"is_active"`
		StartTime    int64   `json:"start_time"`
		EndTime      int64   `json:"end_time"`
		ResetTraffic bool    `json:"reset_traffic"`
		Days         uint64  `json:"days"`
		GiftType     uint8   `json:"gift_type"`
		GiftValue    uint64  `json:"gift_value"`
	}
	QuotaTask {
		Id           int64   `json:"id"`
		Subscribers  []int64 `json:"subscribers"`
		IsActive     *bool   `json:"is_active"`
		StartTime    int64   `json:"start_time"`
		EndTime      int64   `json:"end_time"`
		ResetTraffic bool    `json:"reset_traffic"`
		Days         uint64  `json:"days"`
		GiftType     uint8   `json:"gift_type"`
		GiftValue    uint64  `json:"gift_value"`
		Objects      []int64 `json:"objects"` // UserSubscribe IDs
		Status       uint8   `json:"status"`
		Total        int64   `json:"total"`
		Current      int64   `json:"current"`
		Errors       string  `json:"errors"`
		CreatedAt    int64   `json:"created_at"`
		UpdatedAt    int64   `json:"updated_at"`
	}
	QueryQuotaTaskPreCountRequest {
		Subscribers []int64 `json:"subscribers"`
		IsActive    *bool   `json:"is_active"`
		StartTime   int64   `json:"start_time"`
		EndTime     int64   `json:"end_time"`
	}
	QueryQuotaTaskPreCountResponse {
		Count int64 `json:"count"`
	}
	QueryQuotaTaskListRequest {
		Page   int    `form:"page"`
		Size   int    `form:"size"`
		Status *uint8 `form:"status,omitempty"`
	}
	QueryQuotaTaskListResponse {
		Total int64       `json:"total"`
		List  []QuotaTask `json:"list"`
	}
	QueryQuotaTaskStatusRequest {
		Id int64 `json:"id"`
	}
	QueryQuotaTaskStatusResponse {
		Status  uint8  `json:"status"`
		Current int64  `json:"current"`
		Total   int64  `json:"total"`
		Errors  string `json:"errors"`
	}
)

@server (
	prefix:     v1/admin/marketing
	group:      admin/marketing
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create a batch send email task"
	@handler CreateBatchSendEmailTask
	post /email/batch/send (CreateBatchSendEmailTaskRequest)

	@doc "Get batch send email task list"
	@handler GetBatchSendEmailTaskList
	get /email/batch/list (GetBatchSendEmailTaskListRequest) returns (GetBatchSendEmailTaskListResponse)

	@doc "Stop a batch send email task"
	@handler StopBatchSendEmailTask
	post /email/batch/stop (StopBatchSendEmailTaskRequest)

	@doc "Get pre-send email count"
	@handler GetPreSendEmailCount
	post /email/batch/pre-send-count (GetPreSendEmailCountRequest) returns (GetPreSendEmailCountResponse)

	@doc "Get batch send email task status"
	@handler GetBatchSendEmailTaskStatus
	post /email/batch/status (GetBatchSendEmailTaskStatusRequest) returns (GetBatchSendEmailTaskStatusResponse)

	@doc "Create a quota task"
	@handler CreateQuotaTask
	post /quota/create (CreateQuotaTaskRequest)

	@doc "Query quota task pre-count"
	@handler QueryQuotaTaskPreCount
	post /quota/pre-count (QueryQuotaTaskPreCountRequest) returns (QueryQuotaTaskPreCountResponse)

	@doc "Query quota task list"
	@handler QueryQuotaTaskList
	get /quota/list (QueryQuotaTaskListRequest) returns (QueryQuotaTaskListResponse)
}

