syntax = "v1"

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

import "../types.api"

type (
	PortalPurchaseRequest {
		AuthType       string `json:"auth_type"`
		Identifier     string `json:"identifier"`
		Password       string `json:"password,omitempty"`
		Payment        int64  `json:"payment"`
		SubscribeId    int64  `json:"subscribe_id"`
		Quantity       int64  `json:"quantity"`
		Coupon         string `json:"coupon,omitempty"`
		InviteCode     string `json:"invite_code,omitempty"`
		TurnstileToken string `json:"turnstile_token,omitempty"`
	}
	PortalPurchaseResponse {
		OrderNo string `json:"order_no"`
	}
	GetSubscriptionRequest {
		Language string `form:"language"`
	}
	GetSubscriptionResponse {
		List []Subscribe `json:"list"`
	}
	PrePurchaseOrderRequest {
		Payment     int64  `json:"payment,omitempty"`
		SubscribeId int64  `json:"subscribe_id"`
		Quantity    int64  `json:"quantity"`
		Coupon      string `json:"coupon,omitempty"`
	}
	PrePurchaseOrderResponse {
		Price          int64  `json:"price"`
		Amount         int64  `json:"amount"`
		Discount       int64  `json:"discount"`
		Coupon         string `json:"coupon"`
		CouponDiscount int64  `json:"coupon_discount"`
		FeeAmount      int64  `json:"fee_amount"`
	}
	QueryPurchaseOrderRequest {
		AuthType   string `form:"auth_type"`
		Identifier string `form:"identifier"`
		OrderNo    string `form:"order_no"`
	}
	QueryPurchaseOrderResponse {
		OrderNo        string        `json:"order_no"`
		Subscribe      Subscribe     `json:"subscribe"`
		Quantity       int64         `json:"quantity"`
		Price          int64         `json:"price"`
		Amount         int64         `json:"amount"`
		Discount       int64         `json:"discount"`
		Coupon         string        `json:"coupon"`
		CouponDiscount int64         `json:"coupon_discount"`
		FeeAmount      int64         `json:"fee_amount"`
		Payment        PaymentMethod `json:"payment"`
		Status         uint8         `json:"status"`
		CreatedAt      int64         `json:"created_at"`
		Token          string        `json:"token,omitempty"`
	}
)

@server (
	prefix: v1/public/portal
	group:  public/portal
)
service ppanel {
	@doc "Get available payment methods"
	@handler GetAvailablePaymentMethods
	get /payment-method returns (GetAvailablePaymentMethodsResponse)

	@doc "Get Subscription"
	@handler GetSubscription
	get /subscribe (GetSubscriptionRequest) returns (GetSubscriptionResponse)

	@doc "Pre Purchase Order"
	@handler PrePurchaseOrder
	post /pre (PrePurchaseOrderRequest) returns (PrePurchaseOrderResponse)

	@doc "Purchase subscription"
	@handler Purchase
	post /purchase (PortalPurchaseRequest) returns (PortalPurchaseResponse)

	@doc "Query Purchase Order"
	@handler QueryPurchaseOrder
	get /order/status (QueryPurchaseOrderRequest) returns (QueryPurchaseOrderResponse)

	@doc "Purchase Checkout"
	@handler PurchaseCheckout
	post /order/checkout (CheckoutOrderRequest) returns (CheckoutOrderResponse)
}

