syntax = "v1"

info (
	title:   "File API"
	desc:    "API for ppanel file upload"
	author:  "Codex"
	email:   "codex@openai.com"
	version: "0.0.1"
)

import "../types.api"

type (
	FileUploadRequest {
		BizType string `form:"biz_type" validate:"required"`
	}

	FileUploadResponse {
		Url string `json:"url"`
	}

	FileUploadInitRequest {
		BizType     string `json:"biz_type" validate:"required"`
		FileName    string `json:"file_name" validate:"required"`
		ContentType string `json:"content_type" validate:"required"`
		Size        int64  `json:"size" validate:"required"`
		Sha256      string `json:"sha256"`
	}

	FileUploadInitResponse {
		FileId     string            `json:"file_id"`
		ObjectKey  string            `json:"object_key"`
		UploadURL  string            `json:"upload_url"`
		Method     string            `json:"method"`
		Headers    map[string]string `json:"headers"`
		ExpiredAt  int64             `json:"expired_at"`
	}

	FileUploadCompleteRequest {
		FileId string `json:"file_id" validate:"required"`
	}

	FileUploadCompleteResponse {
		Url string `json:"url"`
	}
)

@server (
	prefix:     v1/public/file
	group:      public/file
	middleware: AuthMiddleware,DeviceMiddleware
)
service ppanel {
	@doc "Upload file to RustFS"
	@handler FileUpload
	post /upload (FileUploadRequest) returns (FileUploadResponse)

	@doc "Init file upload"
	@handler FileUploadInit
	post /upload/init (FileUploadInitRequest) returns (FileUploadInitResponse)

	@doc "Complete file upload"
	@handler FileUploadComplete
	post /upload/complete (FileUploadCompleteRequest) returns (FileUploadCompleteResponse)
}
