package com.cool.store.controller.webc;

import com.cool.store.context.PartnerUserHolder;
import com.cool.store.request.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.PointService;
import com.cool.store.service.ShopService;
import com.cool.store.vo.point.MiniPointPageVO;
import com.cool.store.vo.point.PointDetailVO;
import com.cool.store.vo.point.ShopRentInfoVO;
import com.cool.store.vo.shop.MiniShopPageVO;
import com.cool.store.vo.shop.ShopStageInfoVO;
import com.cool.store.vo.shop.ShopStageVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangchenbiao
 * @FileName: MiniPointController
 * @Description:
 * @date 2024-04-11 16:29
 */
@RestController
@Api(tags ="小程序店铺选址")
@RequestMapping({"/mini/shop"})
public class MiniShopController {

    @Resource
    private ShopService shopService;
    @Resource
    private PointService pointService;

    @ApiOperation("获取店铺列表")
    @GetMapping("/getShopList")
    public ResponseResult<List<MiniShopPageVO>> getShopList() {
        Long lineId = PartnerUserHolder.getUser().getLineId();
        return ResponseResult.success(shopService.getShopList(lineId));
    }

    @ApiOperation("获取店铺的阶段信息")
    @GetMapping("/getShopStageInfo")
    public ResponseResult<List<ShopStageInfoVO>> getShopStageInfo(@RequestParam("shopId")Long shopId, @RequestParam(value = "shopStage", required = false)Integer shopStage) {
        Long lineId = PartnerUserHolder.getUser().getLineId();
        return ResponseResult.success(shopService.getShopStageInfo(shopId, shopStage));
    }

    @ApiOperation("获取阶段/子阶段/子阶段状态枚举")
    @GetMapping("/getShopSubStageStatusEnum")
    public ResponseResult<List<ShopStageVO>> getShopSubStageStatusEnum() {
        return ResponseResult.success(ShopStageVO.getShopStageList());
    }

    @ApiOperation("获取推荐给我的铺位")
    @PostMapping("/getLineRecommendPointPage")
    public ResponseResult<PageInfo<MiniPointPageVO>> getLineRecommendPointPage(@RequestBody MiniPointPageRequest request) {
        Long lineId = PartnerUserHolder.getUser().getLineId();
        request.setLineId(lineId);
        return ResponseResult.success(pointService.getLineRecommendPointPage(request));
    }

    @ApiOperation("铺位详情")
    @GetMapping("/detail")
    public ResponseResult<PointDetailVO> getPointDetailInfo(@RequestParam("pointId")Long pointId,
                                                            @RequestParam(value = "isGetNodeNo", required = false)Boolean isGetNodeNo) {
        return ResponseResult.success(pointService.getPointDetailInfo(pointId, isGetNodeNo));
    }

    @ApiOperation("选择铺位")
    @PostMapping("/selectPoint")
    public ResponseResult<Integer> lineSelectPoint(@RequestBody @Validated SelectPointRequest request) {
        Long lineId = PartnerUserHolder.getUser().getLineId();
        request.setLineId(lineId);
        return ResponseResult.success(pointService.lineSelectPoint(request));
    }

    @ApiOperation("拒绝铺位")
    @PostMapping("/rejectPoint")
    public ResponseResult<Integer> lineRejectPoint(@RequestBody @Validated RejectPointRequest request) {
        Long lineId = PartnerUserHolder.getUser().getLineId();
        request.setLineId(lineId);
        return ResponseResult.success(pointService.lineRejectPoint(request));
    }

    @ApiOperation("提交新铺位")
    @PostMapping("/addPoint")
    public ResponseResult<Long> miniAddPointDetailInfo(@RequestBody @Validated MiniAddPointRequest request) {
        request.setCurLineId(PartnerUserHolder.getUser().getLineId());
        return ResponseResult.success(pointService.miniAddPointDetailInfo(request));
    }

    @ApiOperation("上传租赁合同")
    @PostMapping("/uploadRentContract")
    public ResponseResult<Integer> uploadRentContract(@RequestBody @Validated AddRentContractRequest request) {
        Long lineId = PartnerUserHolder.getUser().getLineId();
        request.setCurLineId(lineId);
        return ResponseResult.success(pointService.uploadRentContract(request));
    }

    @ApiOperation("获取租赁合同详情")
    @GetMapping("/getRentContractDetail")
    public ResponseResult<ShopRentInfoVO> getRentContractDetail(@RequestParam("shopId")Long shopId) {
        return ResponseResult.success(pointService.getRentContractDetail(shopId));
    }

    @ApiOperation("更新租赁合同")
    @PostMapping("/updateRentContract")
    public ResponseResult<Integer> updateRentContract(@RequestBody @Validated UpdateRentContractRequest request) {
        Long lineId = PartnerUserHolder.getUser().getLineId();
        request.setCurLineId(lineId);
        return ResponseResult.success(pointService.updateRentContract(request));
    }


}
