package ink.wgink.login.wechat.controller.app;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.wechat.pojo.vos.update.MiniappUpdatePhoneVO;
import ink.wgink.login.wechat.service.sign.IMiniappSignService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultData;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: MiniappAppController
 * @Description: 小程序APP接口
 * @Author: wanggeng
 * @Date: 2021/8/2 8:19 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "小程序")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/miniapp")
public class MiniappAppController {

    @Autowired
    private IMiniappSignService miniappSignService;

    @ApiOperation(value = "更新电话", notes = "由用户主动授权更新手机号，返回新token")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update-phone")
    @CheckRequestBodyAnnotation
    public SuccessResultData<String> updatePhone(@RequestHeader("token") String token,
                                                 @RequestBody MiniappUpdatePhoneVO miniappUpdatePhoneVO) throws Exception {
        String newToken = miniappSignService.updatePhone(token, miniappUpdatePhoneVO);
        return new SuccessResultData<>(newToken);
    }

}
