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             string `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             string `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  string `form:"scope,omitempty"`
		Status *uint8 `form:"status,omitempty"`
	}
	GetBatchSendEmailTaskListResponse {
		Total int64                `json:"total"`
		List  []BatchSendEmailTask `json:"list"`
	}
	StopBatchSendEmailTaskRequest {
		Id int64 `json:"id"`
	}
	GetPreSendEmailCountRequest {
		Scope             string `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"`
	}
)

@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)
}

