package org.jeecg.modules.xcx.shop.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.xcx.shop.req.*;
import org.jeecg.modules.xcx.shop.service.IShopService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "店铺接口")
@Slf4j
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Resource
    private IShopService shopService;

    @ApiOperation(value = "申请店铺")
    @PostMapping("/apply")
    public Result<?> applyShop(HttpServletRequest request, ApplyShopReq applyShopReq){
        applyShopReq.setToken(TokenUtils.getTokenByRequest(request));
        return shopService.applyShop(applyShopReq);
    }

    @ApiOperation(value = "店铺申请提现")
    @PostMapping("/withdrawal/apply")
    public Result<?> applyWithdrawal(HttpServletRequest request, ApplyWithdrawalReq applyWithdrawalReq){
        applyWithdrawalReq.setToken(TokenUtils.getTokenByRequest(request));
        return shopService.applyWithdrawal(applyWithdrawalReq);
    }

    @ApiOperation(value = "提现日志")
    @GetMapping("/withdrawal/page")
    public Result<?> withdrawalPage(HttpServletRequest request, WithdrawalPageReq withdrawalPageReq){
        withdrawalPageReq.setToken(TokenUtils.getTokenByRequest(request));
        return shopService.withdrawalPage(withdrawalPageReq);
    }

    @ApiOperation(value = "我的用户")
    @GetMapping("/user")
    public Result<?> myUser(HttpServletRequest request, MyUserReq myUserReq){
        myUserReq.setToken(TokenUtils.getTokenByRequest(request));
        return shopService.myUser(myUserReq);
    }

    @ApiOperation(value = "水洗店首页数据")
    @GetMapping("/index")
    public Result<?> shopIndex(HttpServletRequest request){
        return shopService.shopIndex(TokenUtils.getTokenByRequest(request));
    }

    @ApiOperation(value = "获取绑定店铺的数据")
    @GetMapping("/bind")
    public Result<?> getShop(HttpServletRequest request){
        return shopService.getShop(TokenUtils.getTokenByRequest(request));
    }

    @ApiOperation(value = "修改店铺营业时间")
    @PostMapping("/job/time")
    public Result<?> editShopJobTime(HttpServletRequest request, EditShopJobTimeReq editShopJobTimeReq){
        editShopJobTimeReq.setToken(TokenUtils.getTokenByRequest(request));
        return shopService.editShopJobTime(editShopJobTimeReq);
    }

    @ApiOperation(value = "绑定微信")
    @PostMapping("/bind/wx")
    public Result<?> bindWx(HttpServletRequest request, BindWxReq bindWxReq){
        bindWxReq.setToken(TokenUtils.getTokenByRequest(request));
        return shopService.bindWx(bindWxReq);
    }

    @ApiOperation(value = "修改店铺信息")
    @PostMapping("/edit/info")
    public Result<?> editShopInfo(HttpServletRequest request, EditShopInfoReq editShopInfoReq){
        editShopInfoReq.setToken(TokenUtils.getTokenByRequest(request));
        return shopService.editShopInfo(editShopInfoReq);
    }
}
