package com.sqx.modules.errand.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.common.entity.CommonInfo;
import com.sqx.modules.common.service.CommonInfoService;
import com.sqx.modules.errand.entity.Feedback;
import com.sqx.modules.errand.service.AdminTrainingCenterService;
import com.sqx.modules.errand.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/userinfo")
@Api(value = "用户端", tags = {"用户端"})
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private CommonInfoService commonInfoService;
    @Autowired
    private AdminTrainingCenterService adminTrainingCenterService;

    @Login
    @GetMapping(value = "/findUserInfoById")
    @ApiOperation("获取登陆用户信息")
    public Result findUserInfoById(@RequestAttribute("userId") Long userId){
        UserEntity userEntity = userInfoService.findUserInfoById(userId);

        return Result.success().put("data", userEntity);
    }

    @Login
    @PostMapping(value = "/certification")
    @ApiOperation("用户实名认证")
    public Result certification(@RequestAttribute("userId") Long userId, @RequestBody UserEntity userEntity){
        return userInfoService.certification(userId,userEntity);
    }

    @Login
    @ApiOperation("用户绑定手机")
    @PostMapping(value = "/checkPhone")
    public Result checkPhone(String openId, String phone, Integer userType){

        return userInfoService.checkPhone(openId, phone,userType);
    }

    @Login
    @PostMapping(value = "/riderCertification")
    @ApiOperation("骑手实名认证")
    public Result riderCertification(@RequestAttribute Long userId, @RequestBody UserEntity userEntity){
        return userInfoService.riderCertification(userId, userEntity);
    }

    @Login
    @PostMapping(value = "updateUserInfoById")
    @ApiOperation("用户修改信息")
    public Result updateUserInfoById(@RequestAttribute Long userId, @RequestBody UserEntity userEntity){
        userEntity.setUserId(userId);
        return userInfoService.updateUserInfoById(userEntity);
    }
/*

    @Login
    @GetMapping(value = "findAccount")
    @ApiOperation("获取用户账户明细")
    public Result findAccount(@RequestAttribute("userId") Long userId){
        MoneyDetails moneyDetails = userInfoService.findAccount(userId);
        return Result.success().put("data", moneyDetails);
    }
*/

    @Login
    @PostMapping(value = "userFeedback")
    @ApiOperation("用户反馈")
    public Result userFeedback(@RequestAttribute Long userId, @RequestBody Feedback feedback){

        return userInfoService.userFeedback(userId, feedback);
    }


    @GetMapping(value = "userAgreement")
    @ApiOperation("用户协议")
    public Result userAgreement(){
        CommonInfo one = commonInfoService.findOne(245);
        return Result.success().put("data", one);
    }


    @GetMapping(value = "privacyPolicy")
    @ApiOperation("隐私政策")
    public Result privacyPolicy(){
        CommonInfo one = commonInfoService.findOne(246);
        return Result.success().put("data", one);
    }


    @ApiOperation("跑腿代购服务用户协议")
    @GetMapping(value = "serviceAgreement")
    public Result serviceAgreement(){
        CommonInfo one = commonInfoService.findOne(256);
        return Result.success().put("data", one);
    }

    @Login
    @ApiOperation("骑手收入统计 完成订单数统计")
    @GetMapping(value = "findIncome")
    public Result findIncome(@RequestAttribute Long userId){

        return userInfoService.findIncome(userId);
    }

    @Login
    @ApiOperation("获取骑手账户余额")
    @GetMapping(value = "findBalance")
    public Result findBalance(@RequestAttribute Long userId){

        return userInfoService.findBalance(userId);
    }

    @Login
    @ApiOperation("获取骑手保证金")
    @GetMapping(value = "findCashDeposit")
    public Result findCashDeposit(@RequestAttribute Long userId){

        return userInfoService.findCashDeposit(userId);
    }

    @Login
    @ApiOperation("获取骑手账户明细")
    @GetMapping(value = "findMoneyDetails")
    public Result findMoneyDetails(@RequestAttribute Long userId, Integer page, Integer limit, Integer classify){

        return userInfoService.findMoneyDetails(userId,page,limit, classify);
    }

    @Login
    @ApiOperation("骑手查看用户订单评价")
    @GetMapping(value = "findEvaluate")
    public Result findEvaluate(@RequestAttribute Long userId, Integer page, Integer limit, String satisfactionFlag){

        return userInfoService.findEvaluate(userId, page, limit, satisfactionFlag);
    }

    @Login
    @ApiOperation("新用户领取跑腿新人红包")
    @GetMapping(value = "getNewUserRedPacket")
    public Result getNewUserRedPacket(@RequestAttribute Long userId){

        return userInfoService.getNewUserRedPacket(userId);
    }

    @Login
    @ApiOperation("新用户领取外卖新人红包")
    @GetMapping(value = "getNewUserRedPacketWm")
    public Result getNewUserRedPacketWm(@RequestAttribute Long userId){

        return userInfoService.getNewUserRedPacketWm(userId);
    }

    @Login
    @ApiOperation("骑手上线时更新骑手坐标")
    @PostMapping(value = "updateCoordinate")
    public Result updateCoordinate(@RequestAttribute Long userId, double lng, double lat){

        return userInfoService.updateCoordinate(userId, lng, lat);
    }

    @Login
    @ApiOperation("骑手改变上下线状态")
    @PostMapping(value = "updateOnLine")
    public Result updateOnLine(@RequestAttribute Long userId, Integer onLineFlag){

        return userInfoService.updateOnLine(userId, onLineFlag);
    }

    @ApiOperation("接单排行榜")
    @GetMapping(value = "rankingList")
    public Result rankingList(Integer page, Integer limit, String address, String date, String dateType){

        return userInfoService.rankingList(page, limit, address, date, dateType);
    }

    @ApiOperation("培训中心列表")
    @GetMapping(value = "trainingCenterList")
    public Result trainingCenterList(Integer page, Integer limit, String title, Integer type){

        return adminTrainingCenterService.adminTrainingCenter(page, limit, title, type);
    }

    @ApiOperation("帮助中心详情")
    @GetMapping(value = "TrainingCenter")
    public Result TrainingCenter(Long id){

        return adminTrainingCenterService.TrainingCenter(id);
    }

    @Login
    @ApiOperation("判断用户是否被封号")
    @GetMapping(value = "bannedFlag")
    public Result bannedFlag(@RequestAttribute Long userId){

        return userInfoService.bannedFlag(userId);
    }

    @Login
    @ApiOperation("用户保证金明细")
    @GetMapping(value = "selectCashDeposit")
    public Result selectCashDeposit(@RequestAttribute Long userId, Integer page, Integer limit, Integer classify){

        return userInfoService.selectCashDeposit(userId, page, limit, classify);
    }

}
