syntax = "v1"

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

import "../types.api"

type (
	SubscribeApplication {
		Id                int64        `json:"id"`
		Name              string       `json:"name"`
		Description       string       `json:"description,omitempty"`
		Icon              string       `json:"icon,omitempty"`
		Scheme            string       `json:"scheme,omitempty"`
		UserAgent         string       `json:"user_agent"`
		IsDefault         bool         `json:"is_default"`
		SubscribeTemplate string       `json:"template"`
		OutputFormat      string       `json:"output_format"`
		DownloadLink      DownloadLink `json:"download_link,omitempty"`
		CreatedAt         int64        `json:"created_at"`
		UpdatedAt         int64        `json:"updated_at"`
	}
	GetSubscribeApplicationListResponse {
		Total int64                  `json:"total"`
		List  []SubscribeApplication `json:"list"`
	}
	CreateSubscribeApplicationRequest {
		Name              string       `json:"name"`
		Description       string       `json:"description,omitempty"`
		Icon              string       `json:"icon,omitempty"`
		Scheme            string       `json:"scheme,omitempty"`
		UserAgent         string       `json:"user_agent"`
		IsDefault         bool         `json:"is_default"`
		SubscribeTemplate string       `json:"template"`
		OutputFormat      string       `json:"output_format"`
		DownloadLink      DownloadLink `json:"download_link"`
	}
	UpdateSubscribeApplicationRequest {
		Id                int64        `json:"id"`
		Name              string       `json:"name"`
		Description       string       `json:"description,omitempty"`
		Icon              string       `json:"icon,omitempty"`
		Scheme            string       `json:"scheme,omitempty"`
		UserAgent         string       `json:"user_agent"`
		IsDefault         bool         `json:"is_default"`
		SubscribeTemplate string       `json:"template"`
		OutputFormat      string       `json:"output_format"`
		DownloadLink      DownloadLink `json:"download_link,omitempty"`
	}
	DeleteSubscribeApplicationRequest {
		Id int64 `json:"id"`
	}
	GetSubscribeApplicationListRequest {
		Page int `form:"page"`
		Size int `form:"size"`
	}
	PreviewSubscribeTemplateRequest {
		Id int64 `form:"id"`
	}
	PreviewSubscribeTemplateResponse {
		Template string `json:"template"` // 预览的模板内容
	}
)

@server (
	prefix:     v1/admin/application
	group:      admin/application
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create subscribe application"
	@handler CreateSubscribeApplication
	post / (CreateSubscribeApplicationRequest) returns (SubscribeApplication)

	@doc "Update subscribe application"
	@handler UpdateSubscribeApplication
	put /subscribe_application (UpdateSubscribeApplicationRequest) returns (SubscribeApplication)

	@doc "Get subscribe application list"
	@handler GetSubscribeApplicationList
	get /subscribe_application_list (GetSubscribeApplicationListRequest) returns (GetSubscribeApplicationListResponse)

	@doc "Delete subscribe application"
	@handler DeleteSubscribeApplication
	delete /subscribe_application (DeleteSubscribeApplicationRequest)

	@doc "Preview Template"
	@handler PreviewSubscribeTemplate
	get /preview (PreviewSubscribeTemplateRequest) returns (PreviewSubscribeTemplateResponse)
}

