package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.dto.BatchStatusRefreshDTO;
import com.cool.store.dto.OpenInfoDTO;
import com.cool.store.dto.TransferLogDTO;
import com.cool.store.dto.UserDTO;
import com.cool.store.request.*;
import com.cool.store.response.BranchShopDetailResponse;
import com.cool.store.response.BranchShopResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.response.bigdata.ApiResponse;
import com.cool.store.service.OpenApiService;
import com.cool.store.service.ShopService;
import com.cool.store.service.TransferLogService;
import com.cool.store.vo.shop.MiniShopPageVO;
import com.cool.store.vo.shop.ShopStageInfoVO;
import com.cool.store.vo.shop.StageShopCountVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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: PCShopController
 * @Description:
 * @date 2024-04-16 14:44
 */
@Api(tags = "pc店铺")
@RestController
@RequestMapping("/pc/shop")
public class PCShopController {

    @Resource
    private ShopService shopService;
    @Resource
    private TransferLogService transferLogService;
    @Resource
    private OpenApiService openApiService;

    @ApiOperation("获取店铺列表")
    @GetMapping("/getShopList")
    public ResponseResult<List<MiniShopPageVO>> getShopList(@RequestParam("lineId") Long lineId) {
        return ResponseResult.success(shopService.getShopList(lineId, CurrentUserHolder.getUserId()));
    }

    @ApiOperation("获取各个阶段店铺数量")
    @GetMapping("/getStageShopCount")
    public ResponseResult<StageShopCountVO> getStageShopCount(@RequestParam("lineId") Long lineId) {
        return ResponseResult.success(shopService.getStageShopCount(lineId));
    }

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

    @ApiOperation("删除店铺")
    @PostMapping("/deleteShop")
    public ResponseResult<Integer> deleteShop(@RequestBody @Validated DeleteShopRequest request) {
        request.setUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(shopService.deleteShop(request));
    }

    @ApiOperation("新增店铺")
    @PostMapping("/addShop")
    public ResponseResult<Long> addShop(@RequestBody @Validated AddShopRequest request) {
        request.setUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(shopService.addShop(request));
    }

    @ApiOperation("修改门店编号和门店名称和门店所属区域")
    @PostMapping("/updateShopCode")
    public ResponseResult<Integer> updateShopCode(@RequestBody @Validated UpdateShopCodeRequest request) {
        return ResponseResult.success(shopService.updateShopCode(request, CurrentUserHolder.getUserId()));
    }

    @ApiOperation("新建分店")
    @PostMapping("/addBranchShop")
    public ResponseResult<Long> addBranchShop(@RequestBody @Validated AddBranchShopRequest request) {
        String userId = CurrentUserHolder.getUserId();
        return ResponseResult.success(shopService.addBranchShop(request, userId));
    }

    @ApiOperation("开店详情/左边小窗")
    @GetMapping("/getBranchShopDetail")
    public ResponseResult<BranchShopDetailResponse> getBranchShopDetail(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(shopService.getBranchShopDetail(shopId));
    }

    @ApiOperation("修改开店详情/左边小窗")
    @PostMapping("/updateBranchShopDetail")
    public ResponseResult<Integer> updateBranchShopDetail(@RequestBody @Validated BranchShopDetailRequest request) {
        String userId = CurrentUserHolder.getUserId();
        return ResponseResult.success(shopService.updateBranchShopDetail(request, userId));
    }

    @ApiOperation("门店转让，修改门店招商专员/督导")
    @GetMapping("/updateShopInvestment")
    public ResponseResult<Integer> updateShopInvestment(@RequestParam("shopId") Long shopId, @RequestParam("updateUserId") String updateUserId) {
        String userId = CurrentUserHolder.getUserId();
        return ResponseResult.success(shopService.updateShopInvestment(shopId, updateUserId, userId));
    }

    @ApiOperation("门店转让运营顾问")
    @GetMapping("/updateOperationsConsultant")
    public ResponseResult<Boolean> updateOperationsConsultant(@RequestParam("shopId") Long shopId, @RequestParam("updateUserId") String updateUserId) {
        return ResponseResult.success(shopService.updateOperationsConsultant(shopId, updateUserId));
    }

    @ApiOperation("门店转让记录")
    @GetMapping("/getTransferLogPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "线索id", required = true),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "大小", required = true),
            @ApiImplicitParam(name = "lineShopType", value = "1-线索，2-门店", required = true)
    })
    public ResponseResult<PageInfo<TransferLogDTO>> getTransferLogPage(@RequestParam("lineId") Long lineId,
                                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                       @RequestParam(value = "lineShopType", defaultValue = "1") Integer lineShopType) {
        return ResponseResult.success(transferLogService.getTransferLogPage(pageNum, pageSize, lineId, lineShopType));
    }

    @ApiOperation("门店结束跟进")
    @GetMapping("/shopClose")
    public ResponseResult<Boolean> shopClose(@RequestParam("shopId")Long shopId) {
        return ResponseResult.success(shopService.shopClose(shopId));
    }

    @ApiOperation("门店恢复状态")
    @GetMapping("/updateShopStatue")
    public ResponseResult<Boolean> updateShopStatue(@RequestParam("shopId")Long shopId) {
        return ResponseResult.success(shopService.updateShopStatue(shopId));
    }

    @ApiOperation("数据处理专用 处理shop 省市区")
    @GetMapping("/dateHandler")
    public ResponseResult<Integer> dateHandler(@RequestParam("pageSize")Integer  pageSize,@RequestParam("pageNum")Integer pageNum) {
        return ResponseResult.success(shopService.dateHandler(pageNum,pageSize));
    }


    @ApiOperation("获取意向阶段处理人信息")
    @GetMapping("/getIntendSubStageHandle")
    public ResponseResult<List<UserDTO>> getIntendSubStageHandle(@RequestParam("lineId")Long  lineId,
                                                     @RequestParam("subStage")Integer subStage) {
        return ResponseResult.success(shopService.getIntendSubStageHandle(lineId,subStage));
    }


    @ApiOperation("获取筹建阶段处理人信息")
    @GetMapping("/getSubStageHandle")
    public ResponseResult<List<UserDTO>> getSubStageHandle(@RequestParam("shopId")Long  shopId,
                                                     @RequestParam("subStage")Integer subStage) {
        return ResponseResult.success(shopService.getSubStageHandle(shopId,subStage));
    }



    @ApiOperation("获取店铺所属品牌")
    @GetMapping("/getFranchiseBrandName")
    public ResponseResult<String> getFranchiseBrandName(@RequestParam(name = "shopId")Long shopId) {
        return ResponseResult.success(shopService.getFranchiseBrandName(shopId));
    }

    @ApiOperation("获取店铺某阶段状态")
    @GetMapping("/getShopStageStatus")
    public ResponseResult<ShopStageInfoVO> getShopStageStatus(@RequestParam("shopId")Long shopId, @RequestParam("subStage")Integer subStage) {
        return ResponseResult.success(shopService.getShopStageStatus(shopId, subStage));
    }

    @ApiOperation("是否展示装修阶段按钮")
    @GetMapping("/isShowButton")
    public ResponseResult<Boolean> isShowButton(@RequestParam("shopId")Long shopId) {
        return ResponseResult.success(shopService.isShowButton(shopId));
    }

    @ApiOperation("确定实际开业时间")
    @PostMapping("/confirmActualOpenDate")
    public ResponseResult<Boolean> confirmActualOpenDate(@RequestBody @Validated OpenDateReportRequest request) {
        return ResponseResult.success(shopService.confirmOpen( request,CurrentUserHolder.getUserId()));
    }

    @ApiOperation("PC开业时间详情")
    @GetMapping("/getShopOpenInfo")
    public ResponseResult<OpenInfoDTO> getShopOpenInfo(@RequestParam("shopId")Long shopId) {
        return ResponseResult.success(shopService.getShopOpenInfo(shopId));
    }

    @ApiOperation("PC提交计划开业时间")
    @PostMapping("/submitPlanOpenDate")
    public ResponseResult<Boolean> getRecommendedOrMyPointList(@RequestBody @Validated OpenDateReportRequest request) {
        return ResponseResult.success(shopService.submitOpenDateReport( request));
    }
}
