syntax = "v1"

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

import "../types.api"

type (
	CreatePaymentMethodRequest {
		Name        string      `json:"name" validate:"required"`
		Platform    string      `json:"platform" validate:"required"`
		Description string      `json:"description"`
		Icon        string      `json:"icon,omitempty"`
		Domain      string      `json:"domain,omitempty"`
		Config      interface{} `json:"config" validate:"required"`
		FeeMode     uint        `json:"fee_mode"`
		FeePercent  int64       `json:"fee_percent,omitempty"`
		FeeAmount   int64       `json:"fee_amount,omitempty"`
		Enable      *bool       `json:"enable" validate:"required"`
	}
	UpdatePaymentMethodRequest {
		Id          int64       `json:"id" validate:"required"`
		Name        string      `json:"name" validate:"required"`
		Platform    string      `json:"platform" validate:"required"`
		Description string      `json:"description"`
		Icon        string      `json:"icon,omitempty"`
		Domain      string      `json:"domain,omitempty"`
		Config      interface{} `json:"config" validate:"required"`
		FeeMode     uint        `json:"fee_mode"`
		FeePercent  int64       `json:"fee_percent,omitempty"`
		FeeAmount   int64       `json:"fee_amount,omitempty"`
		Enable      *bool       `json:"enable" validate:"required"`
	}
	DeletePaymentMethodRequest {
		Id int64 `json:"id" validate:"required"`
	}
	GetPaymentMethodListRequest {
		Page     int    `form:"page"`
		Size     int    `form:"size"`
		Platform string `form:"platform,omitempty"`
		Search   string `form:"search,omitempty"`
		Enable   *bool  `form:"enable,omitempty"`
	}
	GetPaymentMethodListResponse {
		Total int64                 `json:"total"`
		List  []PaymentMethodDetail `json:"list"`
	}
)

@server (
	prefix:     v1/admin/payment
	group:      admin/payment
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create Payment Method"
	@handler CreatePaymentMethod
	post / (CreatePaymentMethodRequest) returns (PaymentConfig)

	@doc "Update Payment Method"
	@handler UpdatePaymentMethod
	put / (UpdatePaymentMethodRequest) returns (PaymentConfig)

	@doc "Delete Payment Method"
	@handler DeletePaymentMethod
	delete / (DeletePaymentMethodRequest)

	@doc "Get Payment Method List"
	@handler GetPaymentMethodList
	get /list (GetPaymentMethodListRequest) returns (GetPaymentMethodListResponse)

	@doc "Get supported payment platform"
	@handler GetPaymentPlatform
	get /platform returns (PlatformResponse)
}