syntax = "v1"

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

type (
	// User login request
	UserLoginRequest {
		Email     string `json:"email" validate:"required"`
		Password  string `json:"password" validate:"required"`
		IP        string `header:"X-Original-Forwarded-For"`
		UserAgent string `header:"User-Agent"`
		CfToken   string `json:"cf_token,optional"`
	}
	// Check user is exist request
	CheckUserRequest {
		Email string `form:"email" validate:"required"`
	}
	// User login response
	CheckUserResponse {
		Exist bool `json:"exist"`
	}
	// User login response
	UserRegisterRequest {
		Email     string `json:"email" validate:"required"`
		Password  string `json:"password" validate:"required"`
		Invite    string `json:"invite,optional"`
		Code      string `json:"code,optional"`
		IP        string `header:"X-Original-Forwarded-For"`
		UserAgent string `header:"User-Agent"`
		CfToken   string `json:"cf_token,optional"`
	}
	// User login response
	ResetPasswordRequest {
		Email     string `json:"email" validate:"required"`
		Password  string `json:"password" validate:"required"`
		Code      string `json:"code,optional"`
		IP        string `header:"X-Original-Forwarded-For"`
		UserAgent string `header:"User-Agent"`
		CfToken   string `json:"cf_token,optional"`
	}
	LoginResponse {
		Token string `json:"token"`
	}
	OAthLoginRequest {
		Method   string `json:"method" validate:"required"` // google, facebook, apple, telegram, github etc.
		Redirect string `json:"redirect"`
	}
	OAuthLoginResponse {
		Redirect string `json:"redirect"`
	}
	OAuthLoginGetTokenRequest {
		Method   string      `json:"method" validate:"required"` // google, facebook, apple, telegram, github etc.
		Callback interface{} `json:"callback" validate:"required"`
	}
	// login request
	TelephoneLoginRequest {
		Telephone         string `json:"telephone" validate:"required"`
		TelephoneCode     string `json:"telephone_code"`
		TelephoneAreaCode string `json:"telephone_area_code" validate:"required"`
		Password          string `json:"password"`
		IP                string `header:"X-Original-Forwarded-For"`
		CfToken           string `json:"cf_token,optional"`
	}
	// Check user is exist request
	TelephoneCheckUserRequest {
		Telephone         string `form:"telephone" validate:"required"`
		TelephoneAreaCode string `json:"telephone_area_code" validate:"required"`
	}
	// User login response
	TelephoneCheckUserResponse {
		Exist bool `json:"exist"`
	}
	// User login response
	TelephoneRegisterRequest {
		Telephone         string `json:"telephone" validate:"required"`
		TelephoneAreaCode string `json:"telephone_area_code" validate:"required"`
		Password          string `json:"password" validate:"required"`
		Invite            string `json:"invite,optional"`
		Code              string `json:"code,optional"`
		IP                string `header:"X-Original-Forwarded-For"`
		CfToken           string `json:"cf_token,optional"`
	}
	// User login response
	TelephoneResetPasswordRequest {
		Telephone         string `json:"telephone" validate:"required"`
		TelephoneAreaCode string `json:"telephone_area_code" validate:"required"`
		Password          string `json:"password" validate:"required"`
		Code              string `json:"code,optional"`
		IP                string `header:"X-Original-Forwarded-For"`
		CfToken           string `json:"cf_token,optional"`
	}
	AppleLoginCallbackRequest {
		Code    string `form:"code"`
		IDToken string `form:"id_token"`
		State   string `form:"state"`
	}
	GoogleLoginCallbackRequest {
		Code  string `form:"code"`
		State string `form:"state"`
	}
)

@server (
	prefix: v1/auth
	group:  auth
)
service ppanel {
	@doc "User login"
	@handler UserLogin
	post /login (UserLoginRequest) returns (LoginResponse)

	@doc "Check user is exist"
	@handler CheckUser
	get /check (CheckUserRequest) returns (CheckUserResponse)

	@doc "User register"
	@handler UserRegister
	post /register (UserRegisterRequest) returns (LoginResponse)

	@doc "Reset password"
	@handler ResetPassword
	post /reset (ResetPasswordRequest) returns (LoginResponse)

	@doc "User Telephone login"
	@handler TelephoneLogin
	post /login/telephone (TelephoneLoginRequest) returns (LoginResponse)

	@doc "Check user telephone is exist"
	@handler CheckUserTelephone
	get /check/telephone (TelephoneCheckUserRequest) returns (TelephoneCheckUserResponse)

	@doc "User Telephone register"
	@handler TelephoneUserRegister
	post /register/telephone (TelephoneRegisterRequest) returns (LoginResponse)

	@doc "Reset password"
	@handler TelephoneResetPassword
	post /reset/telephone (TelephoneResetPasswordRequest) returns (LoginResponse)
}

@server (
	prefix: v1/auth/oauth
	group:  auth/oauth
)
service ppanel {
	@doc "OAuth login"
	@handler OAuthLogin
	post /login (OAthLoginRequest) returns (OAuthLoginResponse)

	@doc "OAuth login get token"
	@handler OAuthLoginGetToken
	post /login/token (OAuthLoginGetTokenRequest) returns (LoginResponse)

	@doc "Apple Login Callback"
	@handler AppleLoginCallback
	post /callback/apple (AppleLoginCallbackRequest)
}

