syntax = "v1"

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

import (
	"../types.api"
)

type (
	UserInfoResponse {
		Id          int64            `json:"id"`
		Balance     int64            `json:"balance"`
		Email       string           `json:"email"`
		RefererId   int64            `json:"referer_id"`
		ReferCode   string           `json:"refer_code"`
		Avatar      string           `json:"avatar"`
		AreaCode    string           `json:"area_code"`
		Telephone   string           `json:"telephone"`
		Devices     []UserDevice     `json:"devices"`
		AuthMethods []UserAuthMethod `json:"auth_methods"`
	}
	UpdatePasswordRequeset {
		Password    string `json:"password"`
		NewPassword string `json:"new_password"`
	}
	DeleteAccountRequest {
		Method string `json:"method" validate:"required" validate:"required,oneof=email telephone device"`
		Code   string `json:"code"`
	}

	GetUserOnlineTimeStatisticsResponse {
		WeeklyStats       []WeeklyStat      `json:"weekly_stats"`
		ConnectionRecords ConnectionRecords `json:"connection_records"`
	}

	WeeklyStat {
		Day     int     `json:"day"`
		DayName string  `json:"day_name"`
		Hours   float64 `json:"hours"`
	}
	ConnectionRecords {
		CurrentContinuousDays   int64 `json:"current_continuous_days"`
		HistoryContinuousDays   int64 `json:"history_continuous_days"`
		LongestSingleConnection int64 `json:"longest_single_connection"`
	}
)

@server (
	prefix:     v1/app/user
	group:      app/user
	middleware: AppMiddleware,AuthMiddleware
)
service ppanel {
	@doc "query user info"
	@handler QueryUserInfo
	get /info returns (UserInfoResponse)

	@doc "Update Password "
	@handler UpdatePassword
	put /password (UpdatePasswordRequeset)

	@doc "Delete Account"
	@handler DeleteAccount
	delete /account (DeleteAccountRequest)

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

	@doc "Get user online time total"
	@handler GetUserOnlineTimeStatistics
	get /online_time/statistics returns (GetUserOnlineTimeStatisticsResponse)

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

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

}