/**
 * @filename:CustomerUserController 2024年04月01日
 * @project trade-client V1.0 Copyright(c) 2024 wanglang Co. Ltd. All right reserved.
 */
package com.trade.client.enterprise.customer.controller;

import com.trade.client.enterprise.customer.domain.CustomerUser;
import com.trade.client.enterprise.customer.domain.model.LoginMo;
import com.trade.client.enterprise.customer.domain.model.RegisterMo;
import com.trade.client.enterprise.customer.service.CustomerUserLoginService;
import com.trade.client.enterprise.customer.service.CustomerUserRemoteService;
import com.trade.client.enterprise.customer.service.CustomerUserService;
import com.trade.common.core.domain.ResponseResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 说明： 客户接口层
 * </P>
 * 
 * @version: V1.0
 * @author: wanglang
 * @date: 2024年04月01日
 */
@Api(tags = "客户接口", value = "客户接口")
@RestController
@RequestMapping("/customerUser")
public class CustomerUserController {

    @Resource
    private CustomerUserService customerUserService;
    @Resource
    private CustomerUserLoginService customerUserLoginService;
    @Resource
    private CustomerUserRemoteService customerUserRemoteService;

    /**
     * 注册接口
     * 
     * @param user 注册信息
     * @return ResponseResult<Boolean>
     */
    @ApiOperation(value = "注册", notes = "客户注册")
    @PostMapping("/register")
    public ResponseResult<Boolean> register(@RequestBody @Valid RegisterMo user) {
        return ResponseResult.success(customerUserService.register(user));
    }

    /**
     * 登录接口
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @ApiOperation(value = "登录", notes = "客户登录")
    @PostMapping("/login")
    public ResponseResult<Map> login(@RequestBody LoginMo loginBody) {
        return ResponseResult.success(customerUserLoginService.login(loginBody));
    }

    /**
     * 获取用户信息
     * 
     * @return
     */
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @GetMapping("/getInfo")
    public ResponseResult<CustomerUser> getInfo() {
        return ResponseResult.success(customerUserService.getCustomerUserInfo());
    }

    /**
     * 更新密码
     * 
     * @param phoneNumber 手机号
     * @param password 密码
     * @param code 验证码
     * @return true/false
     */
    @ApiOperation(value = "忘记密码", notes = "忘记密码更新密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phoneNumber", value = "手机号", dataTypeClass = String.class, example = "13866668888", required = true),
            @ApiImplicitParam(name = "password", value = "密码", dataTypeClass = String.class, example = "1aa2345", required = true),
            @ApiImplicitParam(name = "code", value = "验证码", dataTypeClass = String.class, example = "888888", required = true)
    })
    @PostMapping("/update/pwd")
    public ResponseResult<Boolean> updatePassword(String phoneNumber, String password, String code) {
        return ResponseResult.success(customerUserService.updatePassword(phoneNumber, password, code));
    }

    /**
     * 修改密码
     *
     * @param oldPassword 旧密码
     * @param newPassword 新密码
     * @return true/false
     */
    @ApiOperation(value = "修改密码", notes = "登录后修改密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "oldPassword", value = "旧密码", dataTypeClass = String.class, example = "1aa2345", required = true),
            @ApiImplicitParam(name = "newPassword", value = "新密码", dataTypeClass = String.class, example = "2aa2345", required = true)
    })
    @PostMapping("/modify/pwd")
    public ResponseResult<Boolean> modifyPassword(String oldPassword, String newPassword) {
        return ResponseResult.success(customerUserService.modifyPassword(oldPassword, newPassword));
    }

    /**
     * 修改手机号
     *
     * @param code 旧手机验证码
     * @param newPhoneNumber 新手机号码
     * @param newCode 新手机验证码
     * @return true/false
     */
    @ApiOperation(value = "修改手机号", notes = "修改手机号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "旧手机验证码", dataTypeClass = String.class, example = "888888", required = true),
            @ApiImplicitParam(name = "newPhoneNumber", value = "新手机号码", dataTypeClass = String.class, example = "18866666666", required = true),
            @ApiImplicitParam(name = "newCode", value = "新手机验证码", dataTypeClass = String.class, example = "666666", required = true)
    })
    @PostMapping("/modify/phoneNumber")
    public ResponseResult<Boolean> modifyPhoneNumber(String code, String newPhoneNumber, String newCode) {
        return ResponseResult.success(customerUserService.modifyPhoneNumber(code, newPhoneNumber, newCode));
    }

    /**
     * 新增邮箱-邮箱地址
     *
     * @param email 邮箱
     * @param code 邮箱验证码
     * @param phoneCode 手机号验证码
     * @return true/false
     */
    @ApiOperation(value = "绑定邮箱", notes = "绑定邮箱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "邮箱", dataTypeClass = String.class, example = "22@xxx", required = true),
            @ApiImplicitParam(name = "code", value = "邮箱验证码", dataTypeClass = String.class, example = "888888", required = true),
            @ApiImplicitParam(name = "phoneCode", value = "手机号验证码", dataTypeClass = String.class, example = "666666", required = true)
    })
    @PostMapping("/binding/email")
    public ResponseResult<Boolean> bindingEmail(String email, String code, String phoneCode) {
        return ResponseResult.success(customerUserService.bindingEmail(email, code, phoneCode));
    }

    /**
     * 修改邮箱
     *
     * @param email 新邮箱
     * @param code 新邮箱验证码
     * @param emailCode 旧邮箱验证码
     * @return: true/false
     */
    @ApiOperation(value = "修改邮箱", notes = "修改邮箱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "邮箱", dataTypeClass = String.class, example = "22@xxx", required = true),
            @ApiImplicitParam(name = "code", value = "新邮箱验证码", dataTypeClass = String.class, example = "888888", required = true),
            @ApiImplicitParam(name = "emailCode", value = "当前邮箱验证码", dataTypeClass = String.class, example = "666666", required = true)
    })
    @PostMapping("/modify/email")
    public ResponseResult<Boolean> modifyEmail(String email, String code, String emailCode) {
        return ResponseResult.success(customerUserService.modifyEmail(email, code, emailCode));
    }

    /**
     * 查询注册时的推荐码
     *
     * @param suffix
     * @return 注册码
     */
    @ApiOperation(value = "查询注册时的推荐码", notes = "查询注册时的推荐码")
    @GetMapping("/getReferralCode")
    public ResponseResult<String> doGetReferralCode(String suffix) {
        return customerUserRemoteService.getReferralCode(suffix);
    }
}
