syntax = "v1"

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

import (
	"../types.api"
)

type (
	AppAuthCheckRequest {
		Method     string `json:"method" validate:"required" validate:"required,oneof=device email mobile"`
		Account    string `json:"account"`
		Identifier string `json:"identifier" validate:"required"`
		UserAgent  string `json:"user_agent" validate:"required,oneof=windows mac linux android ios harmony"`
		AreaCode   string `json:"area_code"`
	}
	AppAuthCheckResponse {
		Status bool
	}
	AppAuthRequest {
		Method     string `json:"method" validate:"required" validate:"required,oneof=device email mobile"`
		Account    string `json:"account"`
		Password   string `json:"password"`
		Identifier string `json:"identifier" validate:"required"`
		UserAgent  string `json:"user_agent" validate:"required,oneof=windows mac linux android ios harmony"`
		Code       string `json:"code"`
		Invite     string `json:"invite"`
		AreaCode   string `json:"area_code"`
		CfToken    string `json:"cf_token,optional"`
	}
	AppAuthRespone {
		Token string `json:"token"`
	}
	AppSendCodeRequest {
		Method   string `json:"method" validate:"required" validate:"required,oneof=email mobile"`
		Account  string `json:"account"`
		AreaCode string `json:"area_code"`
		CfToken  string `json:"cf_token,optional"`
	}
	AppSendCodeRespone {
		Status bool   `json:"status"`
		Code   string `json:"code,omitempty"`
	}
	AppConfigRequest {
		UserAgent string `json:"user_agent" validate:"required,oneof=windows mac linux android ios harmony"`
	}
	AppConfigResponse {
		EncryptionKey          string   `json:"encryption_key"`
		EncryptionMethod       string   `json:"encryption_method"`
		Domains                []string `json:"domains"`
		StartupPicture         string   `json:"startup_picture"`
		StartupPictureSkipTime int64    `json:"startup_picture_skip_time"`
		Application            AppInfo  `json:"applications"`
		OfficialEmail          string   `json:"official_email"`
		OfficialWebsite        string   `json:"official_website"`
		OfficialTelegram       string   `json:"official_telegram"`
		OfficialTelephone      string   `json:"official_telephone"`
		InvitationLink         string   `json:"invitation_link"`
		KrWebsiteId            string   `json:"kr_website_id"`
	}
	AppInfo {
		Id                 int64  `json:"id"`
		Name               string `json:"name"`
		Description        string `json:"description"`
		Url                string `json:"url"`
		Version            string `json:"version"`
		VersionDescription string `json:"version_description"`
		IsDefault          bool   `json:"is_default"`
	}
)

@server(
	prefix:     v1/app/auth
	group:      app/auth
	middleware: AppMiddleware
)
service ppanel {
	@doc "Check Account"
	@handler Check
	post /check (AppAuthCheckRequest) returns (AppAuthCheckResponse)

	@doc "Login"
	@handler Login
	post /login (AppAuthRequest) returns (AppAuthRespone)

	@doc "Register"
	@handler Register
	post /register (AppAuthRequest) returns (AppAuthRespone)

	@doc "Reset Password"
	@handler ResetPassword
	post /reset_password (AppAuthRequest) returns (AppAuthRespone)

	@doc "GetAppConfig"
	@handler GetAppConfig
	post /config (AppConfigRequest) returns (AppConfigResponse)
}