syntax = "v1"

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

import "../types.api"

type (
	CreateDocumentRequest {
		Title   string   `json:"title" validate:"required"`
		Content string   `json:"content" validate:"required"`
		Tags    []string `json:"tags,omitempty" `
		Show    *bool    `json:"show"`
	}
	UpdateDocumentRequest {
		Id      int64    `json:"id" validate:"required"`
		Title   string   `json:"title" validate:"required"`
		Content string   `json:"content" validate:"required"`
		Tags    []string `json:"tags,omitempty" `
		Show    *bool    `json:"show"`
	}
	DeleteDocumentRequest {
		Id int64 `json:"id" validate:"required"`
	}
	BatchDeleteDocumentRequest {
		Ids []int64 `json:"ids" validate:"required"`
	}
	GetDocumentListRequest {
		Page   int64  `form:"page" validate:"required"`
		Size   int64  `form:"size" validate:"required"`
		Tag    string `form:"tag,omitempty"`
		Search string `form:"search,omitempty"`
	}
	GetDocumentListResponse {
		Total int64      `json:"total"`
		List  []Document `json:"list"`
	}
	GetDocumentDetailRequest {
		Id int64 `json:"id" validate:"required"`
	}
)

@server (
	prefix:     v1/admin/document
	group:      admin/document
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create document"
	@handler CreateDocument
	post / (CreateDocumentRequest)

	@doc "Update document"
	@handler UpdateDocument
	put / (UpdateDocumentRequest)

	@doc "Delete document"
	@handler DeleteDocument
	delete / (DeleteDocumentRequest)

	@doc "Batch delete document"
	@handler BatchDeleteDocument
	delete /batch (BatchDeleteDocumentRequest)

	@doc "Get document list"
	@handler GetDocumentList
	get /list (GetDocumentListRequest) returns (GetDocumentListResponse)

	@doc "Get document detail"
	@handler GetDocumentDetail
	get /detail (GetDocumentDetailRequest) returns (Document)
}

