syntax = "v1"

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

import (
	"../types.api"
)

type (
	// GetUserListRequest
	GetUserListRequest {
		Page              int    `form:"page"`
		Size              int    `form:"size"`
		Search            string `form:"search,omitempty"`
		UserId            *int64 `form:"user_id,omitempty"`
		Unscoped          bool   `form:"unscoped,omitempty"`
		SubscribeId       *int64 `form:"subscribe_id,omitempty"`
		UserSubscribeId   *int64 `form:"user_subscribe_id,omitempty"`
		ShortCode         string `form:"short_code,omitempty"`
		DeviceId          *int64 `form:"device_id,omitempty"`
		FamilyJoined      *bool  `form:"family_joined,omitempty"`
		FamilyStatus      string `form:"family_status,omitempty"`
		FamilyOwnerUserId *int64 `form:"family_owner_user_id,omitempty"`
		FamilyId          *int64 `form:"family_id,omitempty"`
		SortOrder         string `form:"sort_order,omitempty"`
	}
	// GetUserListResponse
	GetUserListResponse {
		Total int64  `json:"total"`
		List  []User `json:"list"`
	}
	// GetUserDetail
	GetDetailRequest {
		Id int64 `form:"id" validate:"required"`
	}
	UpdateUserBasiceInfoRequest {
		UserId             int64   `json:"user_id" validate:"required"`
		Password           string  `json:"password"`
		Avatar             string  `json:"avatar"`
		Balance            *int64  `json:"balance"`
		Commission         *int64  `json:"commission"`
		ReferralPercentage uint8   `json:"referral_percentage"`
		OnlyFirstPurchase  *bool   `json:"only_first_purchase"`
		GiftAmount         *int64  `json:"gift_amount"`
		Telegram           int64   `json:"telegram"`
		ReferCode          string  `json:"refer_code"`
		RefererId          *int64  `json:"referer_id"`
		Enable             *bool   `json:"enable"`
		IsAdmin            *bool   `json:"is_admin"`
		Remark             *string `json:"remark"`
	}
	UpdateUserNotifySettingRequest {
		UserId                int64 `json:"user_id" validate:"required"`
		EnableBalanceNotify   bool  `json:"enable_balance_notify"`
		EnableLoginNotify     bool  `json:"enable_login_notify"`
		EnableSubscribeNotify bool  `json:"enable_subscribe_notify"`
		EnableTradeNotify     bool  `json:"enable_trade_notify"`
	}
	CreateUserRequest {
		Email              string `json:"email"`
		Telephone          string `json:"telephone"`
		TelephoneAreaCode  string `json:"telephone_area_code"`
		Password           string `json:"password"`
		ProductId          int64  `json:"product_id"`
		Duration           int64  `json:"duration"`
		ReferralPercentage uint8  `json:"referral_percentage"`
		OnlyFirstPurchase  bool   `json:"only_first_purchase"`
		RefererUser        string `json:"referer_user"`
		ReferCode          string `json:"refer_code"`
		Balance            int64  `json:"balance"`
		Commission         int64  `json:"commission"`
		GiftAmount         int64  `json:"gift_amount"`
		IsAdmin            bool   `json:"is_admin"`
	}
	BatchDeleteUserRequest {
		Ids []int64 `json:"ids" validate:"required"`
	}
	DeleteUserDeivceRequest {
		Id int64 `json:"id"`
	}
	KickOfflineRequest {
		Id int64 `json:"id"`
	}
	CreateUserAuthMethodRequest {
		UserId         int64  `json:"user_id"`
		AuthType       string `json:"auth_type"`
		AuthIdentifier string `json:"auth_identifier"`
	}
	DeleteUserAuthMethodRequest {
		UserId   int64  `json:"user_id"`
		AuthType string `json:"auth_type"`
	}
	UpdateUserAuthMethodRequest {
		UserId         int64  `json:"user_id"`
		AuthType       string `json:"auth_type"`
		AuthIdentifier string `json:"auth_identifier"`
	}
	GetUserAuthMethodRequest {
		UserId int64 `json:"user_id"`
	}
	GetUserAuthMethodResponse {
		AuthMethods []UserAuthMethod `json:"auth_methods"`
	}
	GetUserSubscribeListRequest {
		Page   int   `form:"page"`
		Size   int   `form:"size"`
		UserId int64 `form:"user_id"`
	}
	GetUserSubscribeListResponse {
		List  []UserSubscribe `json:"list"`
		Total int64           `json:"total"`
	}
	GetUserSubscribeLogsRequest {
		Page        int   `form:"page"`
		Size        int   `form:"size"`
		UserId      int64 `form:"user_id"`
		SubscribeId int64 `form:"subscribe_id,omitempty"`
	}
	GetUserSubscribeLogsResponse {
		List  []UserSubscribeLog `json:"list"`
		Total int64              `json:"total"`
	}
	GetUserSubscribeDevicesRequest {
		Page        int   `form:"page"`
		Size        int   `form:"size"`
		UserId      int64 `form:"user_id"`
		SubscribeId int64 `form:"subscribe_id"`
	}
	GetUserSubscribeDevicesResponse {
		List  []UserDevice `json:"list"`
		Total int64        `json:"total"`
	}
	CreateUserSubscribeRequest {
		UserId       int64  `json:"user_id"`
		ExpiredAt    int64  `json:"expired_at"`
		Traffic      int64  `json:"traffic"`
		SubscribeId  int64  `json:"subscribe_id"`
		SpeedLimit   int64  `json:"speed_limit,optional"`
		TrafficLimit string `json:"traffic_limit,optional"`
	}
	UpdateUserSubscribeRequest {
		UserSubscribeId int64   `json:"user_subscribe_id"`
		SubscribeId     int64   `json:"subscribe_id"`
		Traffic         int64   `json:"traffic"`
		ExpiredAt       int64   `json:"expired_at"`
		Upload          int64   `json:"upload"`
		Download        int64   `json:"download"`
		SpeedLimit      *int64  `json:"speed_limit,omitempty" validate:"omitempty,gte=0"`
		TrafficLimit    *string `json:"traffic_limit,omitempty"`
	}
	GetUserLoginLogsRequest {
		Page   int   `form:"page"`
		Size   int   `form:"size"`
		UserId int64 `form:"user_id"`
	}
	GetUserLoginLogsResponse {
		List  []UserLoginLog `json:"list"`
		Total int64          `json:"total"`
	}
	GetUserSubscribeResetTrafficLogsRequest {
		Page            int   `form:"page"`
		Size            int   `form:"size"`
		UserSubscribeId int64 `form:"user_subscribe_id"`
	}
	GetUserSubscribeResetTrafficLogsResponse {
		List  []ResetSubscribeTrafficLog `json:"list"`
		Total int64                      `json:"total"`
	}
	DeleteUserSubscribeRequest {
		UserSubscribeId int64 `json:"user_subscribe_id" validate:"required,gt=0"`
	}
	GetUserSubscribeByIdRequest {
		Id int64 `form:"id" validate:"required"`
	}
	ToggleUserSubscribeStatusRequest {
		UserSubscribeId int64 `json:"user_subscribe_id"`
	}
	ResetUserSubscribeTrafficRequest {
		UserSubscribeId int64 `json:"user_subscribe_id"`
	}
	GetFamilyListRequest {
		Page        int    `form:"page"`
		Size        int    `form:"size"`
		Keyword     string `form:"keyword,omitempty"`
		Status      string `form:"status,omitempty"`
		OwnerUserId *int64 `form:"owner_user_id,omitempty"`
		FamilyId    *int64 `form:"family_id,omitempty"`
		UserId      *int64 `form:"user_id,omitempty"`
	}
	GetFamilyListResponse {
		List  []FamilySummary `json:"list"`
		Total int64           `json:"total"`
	}
	GetFamilyDetailRequest {
		Id int64 `form:"id" validate:"required"`
	}
	UpdateFamilyMaxMembersRequest {
		FamilyId   int64 `json:"family_id" validate:"required,gt=0"`
		MaxMembers int64 `json:"max_members" validate:"required,gt=0"`
	}
	RemoveFamilyMemberRequest {
		FamilyId int64  `json:"family_id" validate:"required,gt=0"`
		UserId   int64  `json:"user_id" validate:"required,gt=0"`
		Reason   string `json:"reason,omitempty"`
	}
	DissolveFamilyRequest {
		FamilyId int64  `json:"family_id" validate:"required,gt=0"`
		Reason   string `json:"reason,omitempty"`
	}
	GetWithdrawalListRequest {
		Page   int    `form:"page"`
		Size   int    `form:"size"`
		UserId *int64 `form:"user_id,omitempty"`
		Status *uint8 `form:"status,omitempty"`
		Method *uint8 `form:"method,omitempty"`
	}
	GetWithdrawalListResponse {
		List  []WithdrawalLog `json:"list"`
		Total int64           `json:"total"`
	}
	ApproveWithdrawalRequest {
		WithdrawalId int64 `json:"withdrawal_id" validate:"required,gt=0"`
	}
	RejectWithdrawalRequest {
		WithdrawalId int64  `json:"withdrawal_id" validate:"required,gt=0"`
		Reason       string `json:"reason" validate:"required,max=500"`
	}
	GetAdminUserInviteStatsRequest {
		UserId int64 `form:"user_id" validate:"required"`
	}
	GetAdminUserInviteStatsResponse {
		InviteCount        int64 `json:"invite_count"`
		TotalCommission    int64 `json:"total_commission"`
		CurrentCommission  int64 `json:"current_commission"`
		ReferralPercentage uint8 `json:"referral_percentage"`
		OnlyFirstPurchase  bool  `json:"only_first_purchase"`
	}
	GetAdminUserInviteListRequest {
		UserId       int64  `form:"user_id" validate:"required"`
		Page         int    `form:"page"`
		Size         int    `form:"size"`
		Search       string `form:"search"`
		Enable       *int   `form:"enable"`
		UserIdSearch int64  `form:"user_id_search"`
	}
	AdminInvitedUser {
		Id                int64  `json:"id"`
		Avatar            string `json:"avatar"`
		Identifier        string `json:"identifier"`
		Enable            bool   `json:"enable"`
		CreatedAt         int64  `json:"created_at"`
		OrderCount        int64  `json:"order_count"`
		HasPurchased      bool   `json:"has_purchased"`
		InviterCommission int64  `json:"inviter_commission"`
		InviterGiftDays   int64  `json:"inviter_gift_days"`
		InviteeGiftDays   int64  `json:"invitee_gift_days"`
	}
	GetAdminUserInviteListResponse {
		Total int64              `json:"total"`
		List  []AdminInvitedUser `json:"list"`
	}
)

@server (
	prefix:     v1/admin/user
	group:      admin/user
	jwt:        JwtAuth
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Get user list"
	@handler GetUserList
	get /list (GetUserListRequest) returns (GetUserListResponse)

	@doc "Get user detail"
	@handler GetUserDetail
	get /detail (GetDetailRequest) returns (User)

	@doc "Update user basic info"
	@handler UpdateUserBasicInfo
	put /basic (UpdateUserBasiceInfoRequest)

	@doc "Update user notify setting"
	@handler UpdateUserNotifySetting
	put /notify (UpdateUserNotifySettingRequest)

	@doc "Delete user"
	@handler DeleteUser
	delete / (GetDetailRequest)

	@doc "Current user"
	@handler CurrentUser
	get /current returns (User)

	@doc "Batch delete user"
	@handler BatchDeleteUser
	delete /batch (BatchDeleteUserRequest)

	@doc "Create user"
	@handler CreateUser
	post / (CreateUserRequest)

	@doc "User device"
	@handler UpdateUserDevice
	put /device (UserDevice)

	@doc "Delete user device"
	@handler DeleteUserDevice
	delete /device (DeleteUserDeivceRequest)

	@doc "kick offline user device"
	@handler KickOfflineByUserDevice
	put /device/kick_offline (KickOfflineRequest)

	@doc "Create user auth method"
	@handler CreateUserAuthMethod
	post /auth_method (CreateUserAuthMethodRequest)

	@doc "Delete user auth method"
	@handler DeleteUserAuthMethod
	delete /auth_method (DeleteUserAuthMethodRequest)

	@doc "Update user auth method"
	@handler UpdateUserAuthMethod
	put /auth_method (UpdateUserAuthMethodRequest)

	@doc "Get user auth method"
	@handler GetUserAuthMethod
	get /auth_method (GetUserAuthMethodRequest) returns (GetUserAuthMethodResponse)

	@doc "Get user subcribe"
	@handler GetUserSubscribe
	get /subscribe (GetUserSubscribeListRequest) returns (GetUserSubscribeListResponse)

	@doc "Get user subcribe by id"
	@handler GetUserSubscribeById
	get /subscribe/detail (GetUserSubscribeByIdRequest) returns (UserSubscribeDetail)

	@doc "Get user subcribe logs"
	@handler GetUserSubscribeLogs
	get /subscribe/logs (GetUserSubscribeLogsRequest) returns (GetUserSubscribeLogsResponse)

	@doc "Get user subcribe reset traffic logs"
	@handler GetUserSubscribeResetTrafficLogs
	get /subscribe/reset/logs (GetUserSubscribeResetTrafficLogsRequest) returns (GetUserSubscribeResetTrafficLogsResponse)

	@doc "Get user subcribe traffic logs"
	@handler GetUserSubscribeTrafficLogs
	get /subscribe/traffic_logs (GetUserSubscribeTrafficLogsRequest) returns (GetUserSubscribeTrafficLogsResponse)

	@doc "Get user subcribe devices"
	@handler GetUserSubscribeDevices
	get /subscribe/device (GetUserSubscribeDevicesRequest) returns (GetUserSubscribeDevicesResponse)

	@doc "Create user subcribe"
	@handler CreateUserSubscribe
	post /subscribe (CreateUserSubscribeRequest)

	@doc "Update user subcribe"
	@handler UpdateUserSubscribe
	put /subscribe (UpdateUserSubscribeRequest)

	@doc "Delete user subcribe"
	@handler DeleteUserSubscribe
	delete /subscribe (DeleteUserSubscribeRequest)

	@doc "Get user login logs"
	@handler GetUserLoginLogs
	get /login/logs (GetUserLoginLogsRequest) returns (GetUserLoginLogsResponse)

	@doc "Reset user subscribe token"
	@handler ResetUserSubscribeToken
	post /subscribe/reset/token (ResetUserSubscribeTokenRequest)

	@doc "Stop user subscribe"
	@handler ToggleUserSubscribeStatus
	post /subscribe/toggle (ToggleUserSubscribeStatusRequest)

	@doc "Reset user subscribe traffic"
	@handler ResetUserSubscribeTraffic
	post /subscribe/reset/traffic (ResetUserSubscribeTrafficRequest)

	@doc "Get family list"
	@handler GetFamilyList
	get /family/list (GetFamilyListRequest) returns (GetFamilyListResponse)

	@doc "Get family detail"
	@handler GetFamilyDetail
	get /family/detail (GetFamilyDetailRequest) returns (FamilyDetail)

	@doc "Update family max members"
	@handler UpdateFamilyMaxMembers
	put /family/max_members (UpdateFamilyMaxMembersRequest)

	@doc "Remove family member"
	@handler RemoveFamilyMember
	put /family/member/remove (RemoveFamilyMemberRequest)

	@doc "Dissolve family"
	@handler DissolveFamily
	put /family/dissolve (DissolveFamilyRequest)

	@doc "Get withdrawal list"
	@handler GetWithdrawalList
	get /withdrawal/list (GetWithdrawalListRequest) returns (GetWithdrawalListResponse)

	@doc "Approve withdrawal"
	@handler ApproveWithdrawal
	post /withdrawal/approve (ApproveWithdrawalRequest)

	@doc "Reject withdrawal"
	@handler RejectWithdrawal
	post /withdrawal/reject (RejectWithdrawalRequest)

	@doc "Get admin user invite stats"
	@handler GetAdminUserInviteStats
	get /invite/stats (GetAdminUserInviteStatsRequest) returns (GetAdminUserInviteStatsResponse)

	@doc "Get admin user invite list"
	@handler GetAdminUserInviteList
	get /invite/list (GetAdminUserInviteListRequest) returns (GetAdminUserInviteListResponse)
}
