syntax = "v1"

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

import "../types.api"

type (
	GetMessageLogListRequest {
		Page   int    `form:"page"`
		Size   int    `form:"size"`
		Type   uint8  `form:"type"`
		Search string `form:"search,optional"`
	}
	GetMessageLogListResponse {
		Total int64        `json:"total"`
		List  []MessageLog `json:"list"`
	}
	FilterLogParams {
		Page   int    `form:"page"`
		Size   int    `form:"size"`
		Date   string `form:"date,optional"`
		Search string `form:"search,optional"`
	}
	FilterEmailLogResponse {
		Total int64        `json:"total"`
		List  []MessageLog `json:"list"`
	}
	FilterMobileLogResponse {
		Total int64        `json:"total"`
		List  []MessageLog `json:"list"`
	}
	SubscribeLog {
		UserId          int64  `json:"user_id"`
		Token           string `json:"token"`
		UserAgent       string `json:"user_agent"`
		ClientIP        string `json:"client_ip"`
		UserSubscribeId int64  `json:"user_subscribe_id"`
		Timestamp       int64  `json:"timestamp"`
	}
	FilterSubscribeLogRequest {
		FilterLogParams
		UserId          int64 `form:"user_id,optional"`
		UserSubscribeId int64 `form:"user_subscribe_id,optional"`
	}
	FilterSubscribeLogResponse {
		Total int64          `json:"total"`
		List  []SubscribeLog `json:"list"`
	}
	LoginLog {
		UserId    int64  `json:"user_id"`
		Method    string `json:"method"`
		LoginIP   string `json:"login_ip"`
		UserAgent string `json:"user_agent"`
		Success   bool   `json:"success"`
		Timestamp int64  `json:"timestamp"`
	}
	FilterLoginLogRequest {
		FilterLogParams
		UserId int64 `form:"user_id,optional"`
	}
	FilterLoginLogResponse {
		Total int64      `json:"total"`
		List  []LoginLog `json:"list"`
	}
	RegisterLog {
		UserId     int64  `json:"user_id"`
		AuthMethod string `json:"auth_method"`
		Identifier string `json:"identifier"`
		RegisterIP string `json:"register_ip"`
		UserAgent  string `json:"user_agent"`
		Timestamp  int64  `json:"timestamp"`
	}
	FilterRegisterLogRequest {
		FilterLogParams
		UserId int64 `form:"user_id,optional"`
	}
	FilterRegisterLogResponse {
		Total int64         `json:"total"`
		List  []RegisterLog `json:"list"`
	}
	ResetSubscribeLog {
		Type            uint16 `json:"type"`
		UserId          int64  `json:"user_id"`
		UserSubscribeId int64  `json:"user_subscribe_id"`
		OrderNo         string `json:"order_no,omitempty"`
		Timestamp       int64  `json:"timestamp"`
	}
	FilterResetSubscribeLogRequest {
		FilterLogParams
		UserSubscribeId int64 `form:"user_subscribe_id,optional"`
	}
	FilterResetSubscribeLogResponse {
		Total int64               `json:"total"`
		List  []ResetSubscribeLog `json:"list"`
	}
	UserSubscribeTrafficLog {
		SubscribeId int64  `json:"subscribe_id"` // Subscribe ID
		UserId      int64  `json:"user_id"` // User ID
		Upload      int64  `json:"upload"` // Upload traffic in bytes
		Download    int64  `json:"download"` // Download traffic in bytes
		Total       int64  `json:"total"` // Total traffic in bytes (Upload + Download)
		Date        string `json:"date"` // Date in YYYY-MM-DD format
		Details     bool   `json:"details"` // Whether to show detailed traffic
	}
	FilterSubscribeTrafficRequest {
		FilterLogParams
		UserId          int64 `form:"user_id,optional"`
		UserSubscribeId int64 `form:"user_subscribe_id,optional"`
	}
	FilterSubscribeTrafficResponse {
		Total int64                     `json:"total"`
		List  []UserSubscribeTrafficLog `json:"list"`
	}
	ServerTrafficLog {
		ServerId int64  `json:"server_id"` // Server ID
		Upload   int64  `json:"upload"` // Upload traffic in bytes
		Download int64  `json:"download"` // Download traffic in bytes
		Total    int64  `json:"total"` // Total traffic in bytes (Upload + Download)
		Date     string `json:"date"` // Date in YYYY-MM-DD format
		Details  bool   `json:"details"` // Whether to show detailed traffic
	}
	FilterServerTrafficLogRequest {
		FilterLogParams
		ServerId int64 `form:"server_id,optional"`
	}
	FilterServerTrafficLogResponse {
		Total int64              `json:"total"`
		List  []ServerTrafficLog `json:"list"`
	}
	FilterBalanceLogRequest {
		FilterLogParams
		UserId int64 `form:"user_id,optional"`
	}
	FilterBalanceLogResponse {
		Total int64        `json:"total"`
		List  []BalanceLog `json:"list"`
	}
	FilterCommissionLogRequest {
		FilterLogParams
		UserId int64 `form:"user_id,optional"`
	}
	FilterCommissionLogResponse {
		Total int64           `json:"total"`
		List  []CommissionLog `json:"list"`
	}
	OrderRefundLog {
		OrderId                int64  `json:"order_id"`
		OrderNo                string `json:"order_no"`
		OperatorUserId         int64  `json:"operator_user_id"`
		OperatorAuthIdentifier string `json:"operator_auth_identifier,omitempty"`
		TargetUserId           int64  `json:"target_user_id"`
		UserSubscribeId        int64  `json:"user_subscribe_id"`
		RefererUserId          int64  `json:"referer_user_id,omitempty"`
		CommissionAmount       int64  `json:"commission_amount"`
		Reason                 string `json:"reason,omitempty"`
		OrderStatusBefore      uint8  `json:"order_status_before"`
		OrderStatusAfter       uint8  `json:"order_status_after"`
		SubscribeStatusBefore  uint8  `json:"subscribe_status_before"`
		SubscribeStatusAfter   uint8  `json:"subscribe_status_after"`
		SubscribeExpireBefore  int64  `json:"subscribe_expire_before"`
		SubscribeExpireAfter   int64  `json:"subscribe_expire_after"`
		CommissionBefore       int64  `json:"commission_before"`
		CommissionAfter        int64  `json:"commission_after"`
		Timestamp              int64  `json:"timestamp"`
	}
	FilterOrderRefundLogRequest {
		FilterLogParams
		OrderId int64 `form:"order_id,optional"`
		UserId  int64 `form:"user_id,optional"`
	}
	FilterOrderRefundLogResponse {
		Total int64            `json:"total"`
		List  []OrderRefundLog `json:"list"`
	}
	GiftLog {
		Type        uint16 `json:"type"`
		userId      int64  `json:"user_id"`
		OrderNo     string `json:"order_no"`
		SubscribeId int64  `json:"subscribe_id"`
		Amount      int64  `json:"amount"`
		Balance     int64  `json:"balance"`
		Remark      string `json:"remark,omitempty"`
		Timestamp   int64  `json:"timestamp"`
	}
	FilterGiftLogRequest {
		FilterLogParams
		UserId int64 `form:"user_id,optional"`
	}
	FilterGiftLogResponse {
		Total int64     `json:"total"`
		List  []GiftLog `json:"list"`
	}
	TrafficLogDetails {
		Id          int64 `json:"id"`
		ServerId    int64 `json:"server_id"`
		UserId      int64 `json:"user_id"`
		SubscribeId int64 `json:"subscribe_id"`
		Download    int64 `json:"download"`
		Upload      int64 `json:"upload"`
		Timestamp   int64 `json:"timestamp"`
	}
	FilterTrafficLogDetailsRequest {
		FilterLogParams
		ServerId    int64 `form:"server_id,optional"`
		SubscribeId int64 `form:"subscribe_id,optional"`
		UserId      int64 `form:"user_id,optional"`
	}
	FilterTrafficLogDetailsResponse {
		Total int64               `json:"total"`
		List  []TrafficLogDetails `json:"list"`
	}
	LogSetting {
		AutoClear *bool `json:"auto_clear"`
		ClearDays int64 `json:"clear_days"`
	}
	GetErrorLogMessageListRequest {
		Page      int    `form:"page"`
		Size      int    `form:"size"`
		Platform  string `form:"platform,optional"`
		Level     uint8  `form:"level,optional"`
		UserId    int64  `form:"user_id,optional"`
		DeviceId  string `form:"device_id,optional"`
		ErrorCode string `form:"error_code,optional"`
		Keyword   string `form:"keyword,optional"`
		Start     int64  `form:"start,optional"`
		End       int64  `form:"end,optional"`
	}
	ErrorLogMessage {
		Id         int64  `json:"id"`
		Platform   string `json:"platform"`
		AppVersion string `json:"app_version"`
		OsName     string `json:"os_name"`
		OsVersion  string `json:"os_version"`
		DeviceId   string `json:"device_id"`
		UserId     int64  `json:"user_id"`
		SessionId  string `json:"session_id"`
		Level      uint8  `json:"level"`
		ErrorCode  string `json:"error_code"`
		Message    string `json:"message"`
		CreatedAt  int64  `json:"created_at"`
	}
	GetErrorLogMessageListResponse {
		Total int64             `json:"total"`
		List  []ErrorLogMessage `json:"list"`
	}
	GetErrorLogMessageDetailResponse {
		Id         int64  `json:"id"`
		Platform   string `json:"platform"`
		AppVersion string `json:"app_version"`
		OsName     string `json:"os_name"`
		OsVersion  string `json:"os_version"`
		DeviceId   string `json:"device_id"`
		UserId     int64  `json:"user_id"`
		SessionId  string `json:"session_id"`
		Level      uint8  `json:"level"`
		ErrorCode  string `json:"error_code"`
		Message    string `json:"message"`
		Stack      string `json:"stack"`
		ClientIP   string `json:"client_ip"`
		UserAgent  string `json:"user_agent"`
		Locale     string `json:"locale"`
		OccurredAt int64  `json:"occurred_at"`
		CreatedAt  int64  `json:"created_at"`
	}
	GetLogMessageRawRequest {
		Id int64 `form:"id" validate:"required"`
	}
	GetLogMessageRawResponse {
		Id         int64       `json:"id"`
		Platform   string      `json:"platform"`
		AppVersion string      `json:"app_version"`
		OsName     string      `json:"os_name"`
		OsVersion  string      `json:"os_version"`
		DeviceId   string      `json:"device_id"`
		UserId     *int64      `json:"user_id"`
		SessionId  string      `json:"session_id"`
		Level      uint8       `json:"level"`
		ErrorCode  string      `json:"error_code"`
		Message    string      `json:"message"`
		Stack      string      `json:"stack"`
		Context    interface{} `json:"context"`
		ClientIP   string      `json:"client_ip"`
		UserAgent  string      `json:"user_agent"`
		Locale     string      `json:"locale"`
		Digest     string      `json:"digest"`
		OccurredAt int64       `json:"occurred_at"`
		CreatedAt  int64       `json:"created_at"`
	}
)

@server (
	prefix:     v1/admin/log
	group:      admin/log
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Get message log list"
	@handler GetMessageLogList
	get /message/list (GetMessageLogListRequest) returns (GetMessageLogListResponse)

	@doc "Filter email log"
	@handler FilterEmailLog
	get /email/list (FilterLogParams) returns (FilterEmailLogResponse)

	@doc "Filter mobile log"
	@handler FilterMobileLog
	get /mobile/list (FilterLogParams) returns (FilterMobileLogResponse)

	@doc "Filter subscribe log"
	@handler FilterSubscribeLog
	get /subscribe/list (FilterSubscribeLogRequest) returns (FilterSubscribeLogResponse)

	@doc "Filter login log"
	@handler FilterLoginLog
	get /login/list (FilterLoginLogRequest) returns (FilterLoginLogResponse)

	@doc "Filter register log"
	@handler FilterRegisterLog
	get /register/list (FilterRegisterLogRequest) returns (FilterRegisterLogResponse)

	@doc "Filter reset subscribe log"
	@handler FilterResetSubscribeLog
	get /subscribe/reset/list (FilterResetSubscribeLogRequest) returns (FilterResetSubscribeLogResponse)

	@doc "Filter user subscribe traffic log"
	@handler FilterUserSubscribeTrafficLog
	get /subscribe/traffic/list (FilterSubscribeTrafficRequest) returns (FilterSubscribeTrafficResponse)

	@doc "Filter server traffic log"
	@handler FilterServerTrafficLog
	get /server/traffic/list (FilterServerTrafficLogRequest) returns (FilterServerTrafficLogResponse)

	@doc "Filter balance log"
	@handler FilterBalanceLog
	get /balance/list (FilterBalanceLogRequest) returns (FilterBalanceLogResponse)

	@doc "Filter commission log"
	@handler FilterCommissionLog
	get /commission/list (FilterCommissionLogRequest) returns (FilterCommissionLogResponse)

	@doc "Filter order refund log"
	@handler FilterOrderRefundLog
	get /order/refund/list (FilterOrderRefundLogRequest) returns (FilterOrderRefundLogResponse)

	@doc "Filter gift log"
	@handler FilterGiftLog
	get /gift/list (FilterGiftLogRequest) returns (FilterGiftLogResponse)

	@doc "Filter traffic log details"
	@handler FilterTrafficLogDetails
	get /traffic/details (FilterTrafficLogDetailsRequest) returns (FilterTrafficLogDetailsResponse)

	@doc "Get log setting"
	@handler GetLogSetting
	get /setting returns (LogSetting)

	@doc "Update log setting"
	@handler UpdateLogSetting
	post /setting (LogSetting)

	@doc "Get error log message list"
	@handler GetErrorLogMessageList
	get /error_message/list (GetErrorLogMessageListRequest) returns (GetErrorLogMessageListResponse)

	@doc "Get error log message detail"
	@handler GetErrorLogMessageDetail
	get /error_message/detail returns (GetErrorLogMessageDetailResponse)

	@doc "Get log message raw detail (temporary)"
	@handler GetLogMessageRaw
	get /message/detail (GetLogMessageRawRequest) returns (GetLogMessageRawResponse)
}

