package org.jeecg.api.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.api.bean.PageBean;
import org.jeecg.api.service.AppletInfoService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.commonAddress.entity.CommonAddress;
import org.jeecg.modules.commonHelp.entity.CommonHelp;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Api(tags="个人中心")
@RestController
@RequestMapping("/info")
@Slf4j
public class AppletInfoController {

    @Resource
    private AppletInfoService appletInfoService;

    //修改用户信息
    @ApiOperation(value="修改用户信息", notes="修改用户信息")
    @PostMapping("/updateUserInfo")
    public Result<?> updateUserInfo(@RequestHeader("X-Access-Token") String token, String nickName, String headImage, String phone){
        return appletInfoService.updateUserInfo(token,nickName,headImage,phone);
    }

    @ApiOperation(value="获取用户信息", notes="获取用户信息")
    @GetMapping("/getUserInfo")
    public Result<?> getUserInfo(@RequestHeader("X-Access-Token") String token){
        return appletInfoService.getUserInfo(token);
    }

    @ApiOperation(value="获取地址列表", notes="获取地址列表")
    @GetMapping("/getAddressList")
    public Result<?> getAddressList(@RequestHeader("X-Access-Token") String token, PageBean pageBean){
        return appletInfoService.getAddressList(token,pageBean);
    }


    @ApiOperation(value="获取地址详情", notes="获取地址详情")
    @GetMapping("/getAddressInfo")
    public Result<?> getAddressInfo(@RequestHeader("X-Access-Token") String token,String id){
        return appletInfoService.getAddressInfo(token,id);
    }

    @ApiOperation(value="保存或修改地址", notes="保存或修改地址")
    @PostMapping("/saveOrUpdateAddress")
    public Result<?> saveOrUpdateAddress(@RequestHeader("X-Access-Token") String token, CommonAddress commonAddress){
        return appletInfoService.saveOrUpdateAddress(token,commonAddress);
    }



    //修改默认地址
    @ApiOperation(value="修改默认地址", notes="修改默认地址")
    @PostMapping("/updateDefaultAddress")
    public Result<?> updateDefaultAddress(@RequestHeader("X-Access-Token") String token,String id){
        return appletInfoService.updateDefaultAddress(token,id);
    }






    @ApiOperation(value="删除地址", notes="删除地址")
    @PostMapping("/deleteAddress")
    public Result<?> deleteAddress(@RequestHeader("X-Access-Token") String token,String id){
        return appletInfoService.deleteAddress(token,id);
    }


    @ApiOperation(value="获取团队列表", notes="获取团队列表")
    @GetMapping("/getTeamList")
    public Result<?> getTeamList(@RequestHeader("X-Access-Token") String token,Integer state, PageBean pageBean){
        return appletInfoService.getTeamList(token,state,pageBean);
    }


    //获取团队头部信息
    @ApiOperation(value="获取团队头部信息", notes="获取团队头部信息")
    @GetMapping("/getTeamHeader")
    public Result<?> getTeamHeader(@RequestHeader("X-Access-Token") String token){
        return appletInfoService.getTeamHeader(token);
    }




    //提现
    @ApiOperation(value="提现", notes="提现")
    @PostMapping("/openMoney")
    public Result<?> openMoney (@RequestHeader("X-Access-Token") String token, BigDecimal money){
        return appletInfoService.openMoney(token,money);
    }


    @ApiOperation(value="获取流水日志列表", notes="获取流水日志列表")
    @GetMapping("/getLogList")
    public Result<?> getLogList(@RequestHeader("X-Access-Token") String token,String timeDate, PageBean pageBean){
        return appletInfoService.getLogList(token,timeDate,pageBean);
    }

//    @ApiOperation(value="创建二维码", notes="创建二维码")
//    @GetMapping("/createQrCode")
//    public Result<?> createQrCode(@RequestHeader("X-Access-Token") String token){
//        return appletInfoService.createQrCode(token);
//    }


    //获取个人邀请码
    @ApiOperation(value="获取个人邀请码", notes="获取个人邀请码")
    @GetMapping(value = "/createQrCode", produces = MediaType.IMAGE_PNG_VALUE)
    public byte[] createQrCode(String token){
        return appletInfoService.getInviteCode2(token);
    }

    @ApiOperation(value="添加帮助", notes="添加帮助")
    @PostMapping("/addHelp")
    public Result<?> addHelp(@RequestHeader("X-Access-Token") String token, CommonHelp commonHelp){
        return appletInfoService.addHelp(token,commonHelp);
    }


}
