syntax = "v1"

type (
	BillingCheckoutCreateReq {
		PlanId    string `json:"plan_id"`
		RequestId string `json:"request_id"`
	}

	BillingCheckoutData {
		Id                string `json:"id"`
		SessionId         string `json:"session_id"`
		Url               string `json:"url"`
		ExpiresAt         int64  `json:"expires_at"`
		Status            string `json:"status,optional"`
		PaymentStatus     string `json:"payment_status,optional"`
		FulfillmentStatus string `json:"fulfillment_status,optional"`
		PlanId            string `json:"plan_id,optional"`
	}

	BillingCheckoutGetReq {
		Id string `path:"id"`
	}

	BillingSubscriptionData {
		PlanId             string `json:"plan_id"`
		PaidPlanId         string `json:"paid_plan_id,optional"`
		Status             string `json:"status"`
		CustomerId         string `json:"customer_id,optional"`
		SubscriptionId     string `json:"subscription_id,optional"`
		CurrentPeriodStart int64  `json:"current_period_start,optional"`
		CurrentPeriodEnd   int64  `json:"current_period_end,optional"`
		CancelAtPeriodEnd  bool   `json:"cancel_at_period_end"`
		AdminOverride      bool   `json:"admin_override"`
	}

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

@server (
	jwt:        Auth
	group:      billing
	prefix:     /api/v1/billing
	middleware: AuthJWT
)
service gateway {
	@handler CreateBillingCheckoutSession
	post /checkout-sessions (BillingCheckoutCreateReq) returns (BillingCheckoutData)

	@handler GetBillingCheckoutSession
	get /checkout-sessions/:id (BillingCheckoutGetReq) returns (BillingCheckoutData)

	@handler GetBillingSubscription
	get /subscription returns (BillingSubscriptionData)

	@handler CreateBillingPortalSession
	post /portal-sessions returns (BillingPortalData)
}

@server (
	group:      billing
	prefix:     /api/v1/billing
	middleware: StripeRawBody
)
service gateway {
	@handler HandleStripeWebhook
	post /stripe/webhook
}
