syntax = "v1"

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

import "../types.api"

type (
	UpdateUserNotifyRequest {
		EnableBalanceNotify   *bool `json:"enable_balance_notify"`
		EnableLoginNotify     *bool `json:"enable_login_notify"`
		EnableSubscribeNotify *bool `json:"enable_subscribe_notify"`
		EnableTradeNotify     *bool `json:"enable_trade_notify"`
	}
	UpdateUserPasswordRequest {
		Password string `json:"password" validate:"required"`
	}
	QueryUserSubscribeListResponse {
		List  []UserSubscribe `json:"list"`
		Total int64           `json:"total"`
	}
	QueryUserBalanceLogListResponse {
		List  []BalanceLog `json:"list"`
		Total int64        `json:"total"`
	}
	QueryUserCommissionLogListRequest {
		Page int `form:"page"`
		Size int `form:"size"`
	}
	QueryUserCommissionLogListResponse {
		List  []CommissionLog `json:"list"`
		Total int64           `json:"total"`
	}
	BindTelegramResponse {
		Url       string `json:"url"`
		ExpiredAt int64  `json:"expired_at"`
	}
	PreUnsubscribeRequest {
		Id int64 `json:"id"`
	}
	PreUnsubscribeResponse {
		DeductionAmount int64 `json:"deduction_amount"`
	}
	UnsubscribeRequest {
		Id int64 `json:"id"`
	}
	BindOAuthRequest {
		Method   string `json:"method"`
		Redirect string `json:"redirect"`
	}
	BindOAuthResponse {
		Redirect string `json:"redirect"`
	}
	BindOAuthCallbackRequest {
		Method   string      `json:"method"`
		Callback interface{} `json:"callback"`
	}
	GetOAuthMethodsResponse {
		Methods []UserAuthMethod `json:"methods"`
	}
	UnbindOAuthRequest {
		Method string `json:"method"`
	}
	ResetUserSubscribeTokenRequest {
		UserSubscribeId int64 `json:"user_subscribe_id"`
	}
	GetLoginLogRequest {
		Page int `form:"page"`
		Size int `form:"size"`
	}
	GetLoginLogResponse {
		List  []UserLoginLog `json:"list"`
		Total int64          `json:"total"`
	}
	GetSubscribeLogRequest {
		Page int `form:"page"`
		Size int `form:"size"`
	}
	GetSubscribeLogResponse {
		List  []UserSubscribeLog `json:"list"`
		Total int64              `json:"total"`
	}
	UpdateBindMobileRequest {
		AreaCode string `json:"area_code" validate:"required"`
		Mobile   string `json:"mobile" validate:"required"`
		Code     string `json:"code" validate:"required"`
	}
	UpdateBindEmailRequest {
		Email string `json:"email" validate:"required"`
	}
	VerifyEmailRequest {
		Email string `json:"email" validate:"required"`
		Code  string `json:"code" validate:"required"`
	}
)

@server (
	prefix:     v1/public/user
	group:      public/user
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Query User Info"
	@handler QueryUserInfo
	get /info returns (User)

	@doc "Update User Notify"
	@handler UpdateUserNotify
	put /notify (UpdateUserNotifyRequest)

	@doc "Update User Password"
	@handler UpdateUserPassword
	put /password (UpdateUserPasswordRequest)

	@doc "Query User Subscribe"
	@handler QueryUserSubscribe
	get /subscribe returns (QueryUserSubscribeListResponse)

	@doc "Pre Unsubscribe"
	@handler PreUnsubscribe
	post /unsubscribe/pre (PreUnsubscribeRequest) returns (PreUnsubscribeResponse)

	@doc "Unsubscribe"
	@handler Unsubscribe
	post /unsubscribe (UnsubscribeRequest)

	@doc "Query User Balance Log"
	@handler QueryUserBalanceLog
	get /balance_log returns (QueryUserBalanceLogListResponse)

	@doc "Query User Affiliate Count"
	@handler QueryUserAffiliate
	get /affiliate/count returns (QueryUserAffiliateCountResponse)

	@doc "Query User Affiliate List"
	@handler QueryUserAffiliateList
	get /affiliate/list (QueryUserAffiliateListRequest) returns (QueryUserAffiliateListResponse)

	@doc "Bind Telegram"
	@handler BindTelegram
	get /bind_telegram returns (BindTelegramResponse)

	@doc "Unbind Telegram"
	@handler UnbindTelegram
	post /unbind_telegram

	@doc "Query User Commission Log"
	@handler QueryUserCommissionLog
	get /commission_log (QueryUserCommissionLogListRequest) returns (QueryUserCommissionLogListResponse)

	@doc "Bind OAuth"
	@handler BindOAuth
	post /bind_oauth (BindOAuthRequest) returns (BindOAuthResponse)

	@doc "Bind OAuth Callback"
	@handler BindOAuthCallback
	post /bind_oauth/callback (BindOAuthCallbackRequest)

	@doc "Get OAuth Methods"
	@handler GetOAuthMethods
	get /oauth_methods returns (GetOAuthMethodsResponse)

	@doc "Unbind OAuth"
	@handler UnbindOAuth
	post /unbind_oauth (UnbindOAuthRequest)

	@doc "Reset User Subscribe Token"
	@handler ResetUserSubscribeToken
	put /subscribe_token (ResetUserSubscribeTokenRequest)

	@doc "Get Login Log"
	@handler GetLoginLog
	get /login_log (GetLoginLogRequest) returns (GetLoginLogResponse)

	@doc "Get Subscribe Log"
	@handler GetSubscribeLog
	get /subscribe_log (GetSubscribeLogRequest) returns (GetSubscribeLogResponse)

	@doc "Verify Email"
	@handler VerifyEmail
	post /verify_email (VerifyEmailRequest)

	@doc "Update Bind Mobile"
	@handler UpdateBindMobile
	put /bind_mobile (UpdateBindMobileRequest)

	@doc "Update Bind Email"
	@handler UpdateBindEmail
	put /bind_email (UpdateBindEmailRequest)
}

