syntax = "v1"

info(
    title: "素-企业平台.系统后台服务"
    desc: "系统后台管理服务"
    author: "ttt"
    email: "tiptok02@163.com"
    version: "v1"
)

// 后台接口-无验证
@server(
    prefix: v1
    group: auth
    middleware: LogRequest
)
service Core {
    @doc "公司注册"
    @handler systemAuthRegister
    post /auth/company_sign_up(CompanyRegisterRequest) returns (CompanyRegisterResponse)
    @doc "系统用户登录"
    @handler systemAuthLogin
    post /auth/login(AuthLoginRequest) returns (AuthLoginResponse)
}

// 后台接口-验证
@server(
    prefix: v1
    group: auth
    middleware: LogRequest,LoginStatusCheck
    jwt: SystemAuth
)
service Core {
    @doc "系统用户信息"
    @handler systemAuthUserInfo
    post /auth/user_info(UserInfoRequest) returns (UserInfoResponse)
    @doc "修改用户信息"
    @handler systemAuthEditUserInfo
    post /auth/edit_user_info(EditUserInfoRequest) returns (UserInfoResponse)
    @doc "修改密码"
    @handler systemAuthChangePassword
    post /auth/change_password(ChangePasswordRequest) returns (ChangePasswordResponse)
    @doc "重置密码"
    @handler systemAuthResetPassword
    post /auth/reset_password(ResetPasswordRequest) returns (ResetPasswordResponse)
    @doc "系统用户信息"
    @handler systemAuthSwitchCompany
    post /auth/switch_company(SwitchCompanyRequest) returns (AuthLoginResponse)

}

@server(
    prefix: v1
    group: user
    middleware: LogRequest
    jwt: SystemAuth
)
service Core {
    @doc "公司用户列表"
    @handler userCompanyUsers
    post /user/company_users(CompanyUsersRequest) returns (CompanyUsersResponse)
}

type(
    User{
        Id          int64        `json:"id,optional"`                                // 用户ID
        Name        string       `json:"name,optional"`                              // 用户名称
        Phone       string       `json:"phone,optional,omitempty"`                   // 用户手机号
        Avatar      string       `json:"avatar,optional,omitempty"`                 // 头像
        Departments []Department `json:"departments,optional,omitempty"` // 部门列表
    }
)

// 系统公司注册
type(
    CompanyRegisterRequest{
        Name string  `json:"name"` // 公司名称
        Logo string  `json:"logo"` // 公司LOGO
        Phone string `json:"phone"`// 注册人手机号
        Code  string `json:"code"` // 短信验证码
    }
    CompanyRegisterResponse{
        Token string `json:"token"`
    }
)

// 系统用户登录
type(
    AuthLoginRequest{
        Phone           string  `json:"phone,optionale"`      // 手机
        Password        string  `json:"password,optional"`   // 密码
        Code            string  `json:"code,optional"`       // 验证码
        LoginType       string  `json:"loginType"`  // 登录类型 wechat-login whchat-phone-login  phone-password-login phone-smscode-login
    }
    AuthLoginResponse{
        Token string `json:"token"`
    }
)

// 系统用户信息
type(
    UserInfoRequest{
        UserId     int64    `json:"userId,optional"`
        CompanyId  int64    `json:"companyId,optional"`
        EmployeeId int64    `json:"employeeId,optional"`
    }
    UserInfoResponse{
        Id     int64  `json:"id"`     // 用户ID
        Avatar string `json:"avatar"` // 头像
        Name   string `json:"name"`   // 用户名称
        Phone  string `json:"phone"`  // 用户手机号
        Accounts       []AccountInfo   `json:"accounts"` // 账号列表
        Apps           []SystemAppItem `json:"apps"`     // 应用列表
        Menus          []Menu          `json:"menus"`    // 有权限的菜单
    }
    AccountInfo{
        //EmployeeId int64      `json:"employeeId"` // 职员ID
        Company    Company   `json:"company"`    // 公司
        Selected   bool       `json:"selected"`   // 当前选择的账号
    }
)

// 修改用户信息
type(
    EditUserInfoRequest{
        Avatar   *string   `json:"avatar,optional"`   // 头像
        Name     *string   `json:"name,optional"`     // 用户名称
        Phone    *string   `json:"phone,optional"`    // 用户手机号
        //Password *string   `json:"password,optional"` // 密码base64((MD5))
    }
//    UserInfoResponse{
//
//    }
)

// 修改密码
type(
    ChangePasswordRequest{
        OldPassword     string `json:"oldPassword,optional"`     // 旧密码
        NewPassword     string `json:"newPassword"`     // 新密码
        ConfirmPassword string `json:"confirmPassword"` // 确认密码
    }
    ChangePasswordResponse{

    }
)

// 重置密码
type(
    ResetPasswordRequest{
        Code            string `json:"code"`            // 验证码
        NewPassword     string `json:"newPassword"`     // 新密码
        ConfirmPassword string `json:"confirmPassword"` // 确认密码
    }
    ResetPasswordResponse{

    }
)

// 切换公司请求
type(
    SwitchCompanyRequest{
        CompanyId  int64    `json:"companyId,string"` // 公司ID
    }
)

// 公司用户搜索
type(
    CompanyUsersRequest{

    }
    CompanyUsersResponse{
        List []User `json:"list"` // 用户列表
    }
)