package com.fdkankan.ucenter.controller.app;


import com.alibaba.fastjson.JSONObject;
import com.fdkankan.ucenter.annotation.VerifySign;
import com.fdkankan.ucenter.common.Result;
import com.fdkankan.ucenter.service.IUserService;
import com.fdkankan.ucenter.service.impl.AppService;
import com.fdkankan.ucenter.service.impl.AppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ucenter/app/user")
public class AppUserController {

    @Autowired
    AppUserService appUserService;

    /**
     * 获取用户信息
     * phoneNum     用户名
     * cameraType   相机类型
     */
    @PostMapping("/getUserInfo")
    @VerifySign
    public Result getUserInfo(@RequestBody JSONObject param){
        String phoneNum = param.get("phoneNum") == null ? null : param.getString("phoneNum");
        Integer cameraType = param.get("cameraType") == null ? 4 : param.getInteger("cameraType");
        if(cameraType == 4){
            cameraType = 1;
        }
        return Result.success( appUserService.getUserInfo(phoneNum,cameraType));
    }

    /**
     * 修改昵称
     * phoneNum  用户名
     * nickName  昵称
     */
    @PostMapping("/updateNickName")
    @VerifySign
    public Result updateNickName(@RequestBody JSONObject param){
        String phoneNum = param.get("phoneNum") == null ? null : param.getString("phoneNum");
        String nickName = param.get("nickName") == null ? null : param.getString("nickName");
        appUserService.updateNickName(nickName,phoneNum);
        return Result.success(nickName );
    }
    /**
     * 修改用户头像
     * phoneNum  用户名
     * head      头像
     */
    @PostMapping("/uploadHead")
    @VerifySign
    public Result uploadHead(@RequestBody JSONObject param) throws Exception {
        String phoneNum = param.get("phoneNum") == null ? null : param.getString("phoneNum");
        String head = param.get("head") == null ? null : param.getString("head");
        appUserService.uploadHead(phoneNum,head);
        return Result.success();
    }

}
