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 {
		Identifier  string `json:"identifier"`
		Email       string `json:"email" validate:"required"`
		Password    string `json:"password" validate:"required"`
		IP          string `header:"X-Original-Forwarded-For"`
		UserAgent   string `header:"User-Agent"`
		LoginType   string `header:"Login-Type"`
		CfToken     string `json:"cf_token,optional"`
		CaptchaId   string `json:"captcha_id,optional"`
		CaptchaCode string `json:"captcha_code,optional"`
		SliderToken string `json:"slider_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 {
		Identifier  string `json:"identifier"`
		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"`
		LoginType   string `header:"Login-Type"`
		CfToken     string `json:"cf_token,optional"`
		CaptchaId   string `json:"captcha_id,optional"`
		CaptchaCode string `json:"captcha_code,optional"`
		SliderToken string `json:"slider_token,optional"`
	}
	// User reset password request
	ResetPasswordRequest {
		Identifier  string `json:"identifier"`
		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"`
		LoginType   string `header:"Login-Type"`
		CfToken     string `json:"cf_token,optional"`
		CaptchaId   string `json:"captcha_id,optional"`
		CaptchaCode string `json:"captcha_code,optional"`
		SliderToken string `json:"slider_token,optional"`
	}
	// Email login request
	EmailLoginRequest {
		Identifier string `json:"identifier" form:"identifier"`
		Email      string `json:"email" form:"email" validate:"required,email"`
		Code       string `json:"code" form:"code" validate:"required"`
		Invite     string `json:"invite,optional" form:"invite"`
		IP         string `header:"X-Original-Forwarded-For"`
		UserAgent  string `header:"User-Agent"`
		LoginType  string `header:"Login-Type"`
		CfToken    string `json:"cf_token,optional" form:"cf_token"`
	}
	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 {
		Identifier        string `json:"identifier"`
		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"`
		UserAgent         string `header:"User-Agent"`
		LoginType         string `header:"Login-Type"`
		CfToken           string `json:"cf_token,optional"`
		CaptchaId         string `json:"captcha_id,optional"`
		CaptchaCode       string `json:"captcha_code,optional"`
		SliderToken       string `json:"slider_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 {
		Identifier        string `json:"identifier"`
		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"`
		UserAgent         string `header:"User-Agent"`
		LoginType         string `header:"Login-Type,optional"`
		CfToken           string `json:"cf_token,optional"`
		CaptchaId         string `json:"captcha_id,optional"`
		CaptchaCode       string `json:"captcha_code,optional"`
		SliderToken       string `json:"slider_token,optional"`
	}
	// User login response
	TelephoneResetPasswordRequest {
		Identifier        string `json:"identifier"`
		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"`
		UserAgent         string `header:"User-Agent"`
		LoginType         string `header:"Login-Type,optional"`
		CfToken           string `json:"cf_token,optional"`
		CaptchaId         string `json:"captcha_id,optional"`
		CaptchaCode       string `json:"captcha_code,optional"`
		SliderToken       string `json:"slider_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"`
	}
	DeviceLoginRequest {
		Identifier  string `json:"identifier" validate:"required"`
		IP          string `header:"X-Original-Forwarded-For"`
		UserAgent   string `json:"user_agent" validate:"required"`
		CfToken     string `json:"cf_token,optional"`
		ShortCode   string `json:"short_code,optional"`
		BasePayload string `json:"base_payload,optional"`
	}
	GenerateCaptchaResponse {
		Id         string `json:"id"`
		Image      string `json:"image"`
		Type       string `json:"type"`
		BlockImage string `json:"block_image,omitempty"`
	}
	SliderVerifyCaptchaRequest {
		Id    string `json:"id" validate:"required"`
		X     int    `json:"x" validate:"required"`
		Y     int    `json:"y" validate:"required"`
		Trail string `json:"trail"`
	}
	SliderVerifyCaptchaResponse {
		Token string `json:"token"`
	}
)

@server (
	prefix:     v1/auth
	group:      auth
	middleware: DeviceMiddleware
)
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 "Email Login"
	@handler EmailLogin
	post /login/email (EmailLoginRequest) returns (LoginResponse)

	@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 TelephoneRegister
	post /register/telephone (TelephoneRegisterRequest) returns (LoginResponse)

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

	@doc "Device Login"
	@handler DeviceLogin
	post /login/device (DeviceLoginRequest) returns (LoginResponse)

	@doc "Generate captcha"
	@handler GenerateCaptcha
	post /captcha/generate returns (GenerateCaptchaResponse)

	@doc "Verify slider captcha"
	@handler SliderVerifyCaptcha
	post /captcha/slider/verify (SliderVerifyCaptchaRequest) returns (SliderVerifyCaptchaResponse)
}

@server (
	prefix:     v1/auth/admin
	group:      auth/admin
	middleware: DeviceMiddleware
)
service ppanel {
	@doc "Admin login"
	@handler AdminLogin
	post /login (UserLoginRequest) returns (LoginResponse)

	@doc "Admin reset password"
	@handler AdminResetPassword
	post /reset (ResetPasswordRequest) returns (LoginResponse)

	@doc "Generate captcha"
	@handler AdminGenerateCaptcha
	post /captcha/generate returns (GenerateCaptchaResponse)

	@doc "Verify slider captcha"
	@handler AdminSliderVerifyCaptcha
	post /captcha/slider/verify (SliderVerifyCaptchaRequest) returns (SliderVerifyCaptchaResponse)
}

@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)
}
