package com.fdkankan.platform.user.controller.api;

import com.fdkankan.common.constant.ServerCode;
import com.fdkankan.platform.user.request.RequestUser;
import com.fdkankan.platform.user.service.IUserService;
import com.fdkankan.platform.user.vo.ReceiverInfoVo;
import com.fdkankan.platform.user.vo.ResponseUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 个人中心
 */
@RestController
@RequestMapping("/service/platform/user")
public class UserController {

    private static Logger log = LoggerFactory.getLogger("programLog");
    @Autowired
    private IUserService userService;


    @RequestMapping(value = "/checkToken", method = RequestMethod.POST)
    public String checkToken() {
        return ServerCode.SUCCESS.message();
    }

    /**
     * 获取用户信息
     */
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.POST)
    public ResponseUser getUserInfo(@RequestBody RequestUser user, @RequestHeader String token) throws Exception {
        return userService.getUserInfoByParam(user,token);
    }

    /**
     * 修改密码
     */
    @RequestMapping(value = "/changePassword", method = RequestMethod.POST)
    public String changePassword(@RequestBody RequestUser user){
        return userService.changePassword(user);
    }

    /**
     * 用户上传头像
     * imgdata 图片的base64码
     */
    @RequestMapping(value = "/uploadHead", method = RequestMethod.POST)
    public String uploadHead(@RequestBody RequestUser user,@RequestHeader String token) throws Exception {
        return userService.uploadHead(user,token);
    }

    /**
     * 用户新增收货地址
     * shipAddress      收货地址-详细地址
     * shipAreaPath     收货地址-省-市-区
     * province         所在地区-省
     * city             所在地区-市
     * shipName         收货人
     * shipMobile       收货人手机
     */
    @RequestMapping(value = "/insertAddress", method = RequestMethod.POST)
    public String insertAddress(@RequestBody RequestUser user,@RequestHeader String token){
        return userService.insertAddress(user,token);
    }

    /**
     * 用户更新默认地址
     * id
     * shipAddress      收货地址-详细地址
     * shipAreaPath     收货地址-省-市-区
     * province         所在地区-省
     * city             所在地区-市
     * shipName         收货人
     * shipMobile       收货人手机
     * setDefault       1表示默认地址，0表示不是默认地址
     */
    @RequestMapping(value = "/updateAddress", method = RequestMethod.POST)

    public String updateAddress(@RequestBody RequestUser user,@RequestHeader String token){
        return userService.updateDefaultAddress(user,token);
    }

    /**
     * 获取用户默认收货信息
     */
    @RequestMapping(value = "/getReceiverInfo", method = RequestMethod.POST)
    public ReceiverInfoVo getReceiverInfo(@RequestHeader String token){
        return  userService.getUserDefaultReceiver(token);
    }

    /**
     * 获取用户收货信息列表
     */
    @RequestMapping(value = "/getReceiverList", method = RequestMethod.POST)
    public List<ReceiverInfoVo> getReceiverList(@RequestHeader String token){
        return userService.getReceiverList(token);
    }

    /**
     * 用户删除默认地址
     */
    @RequestMapping(value = "/deleteAddress", method = RequestMethod.POST)
    public String deleteAddress(@RequestBody RequestUser user){
        return userService.removeAddress(user.getId());
    }
    /**
     * 用户更新邮箱地址
     * email        邮箱地址
     */
    @RequestMapping(value = "/updateEmail", method = RequestMethod.POST)
    public String updateEmail(@RequestBody RequestUser user,@RequestHeader String token){
        return userService.updateEmail(user,token);
    }

    /**
     * 更改昵称
     * nickName     用户昵称
     */
    @RequestMapping(value = "/updateNickName", method = RequestMethod.POST)
    public String updateNickName(@RequestBody RequestUser user,@RequestHeader String token){
        return userService.updateNickName(user,token);
    }
    /**
     * 修改用户信息
     * nickName     昵称
     * email        邮箱
     * isNotice     isNotice
     */
    @RequestMapping(value = "/updateUserDetail", method = RequestMethod.POST)
    public String updateUserDetail(@RequestBody RequestUser user,@RequestHeader String token){
        return userService.updateUserDetail(user,token);
    }
}
