package com.cool.store.controller.webb;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.context.CurrentUserHolder;
import com.cool.store.request.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.PointService;
import com.cool.store.vo.LinePointBaseInfoVO;
import com.cool.store.vo.point.*;
import com.cool.store.vo.shop.ShopStageVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author zhangchenbiao
 * @FileName: ShopPointController
 * @Description:
 * @date 2024-03-29 15:36
 */
@Slf4j
@Api(tags = "选址&铺位")
@RestController
@RequestMapping("/pc/point")
public class PointController {

    @Resource
    private PointService pointService;

    @ApiOperation("新增铺位")
    @PostMapping("/add")
    public ResponseResult<Long> addPointDetailInfo(@RequestBody @Validated AddPointDetailRequest shopPointDetailRequest) {
        log.info("新增铺位：{}", JSONObject.toJSONString(shopPointDetailRequest));
        return ResponseResult.success(pointService.addPointDetailInfo(shopPointDetailRequest, CurrentUserHolder.getUserId()));
    }

    @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("/update")
    public ResponseResult<Long> updatePointDetailInfo(@RequestBody @Validated UpdatePointDetailRequest shopPointDetailRequest) {
        return ResponseResult.success(pointService.updatePointDetailInfo(shopPointDetailRequest));
    }

    @ApiOperation("生成评估报告")
    @PostMapping("/generateEvaluationReport")
    public ResponseResult<Integer> generateEvaluationReport(@RequestBody PointIdRequest request) {
        return ResponseResult.success(pointService.generateEvaluationReport(request.getPointId()));
    }

    @ApiOperation("铺位失效")
    @PostMapping("/invalid")
    public ResponseResult<Integer> pointInvalid(@RequestBody PointIdRequest request) {
        return ResponseResult.success(pointService.pointInvalid(request.getPointId()));
    }

    @ApiOperation("铺位解绑")
    @PostMapping("/unbind")
    public ResponseResult<Integer> pointUnbind(@RequestBody PointIdRequest request) {
        return ResponseResult.success(pointService.pointUnbind(request.getPointId()));
    }

    @ApiOperation("配置高德评估报告")
    @PostMapping("/addMapEvaluationReport")
    public ResponseResult<Integer> addMapEvaluationReport(@RequestBody AddMapEvaluationReportRequest request) {
        return ResponseResult.success(pointService.addMapEvaluationReport(request));
    }

    @ApiOperation("选址人员提交审批")
    @PostMapping("/submitAudit")
    public ResponseResult<Integer> submitAudit(@RequestBody @Validated SubmitPointAuditRequest request) {
        return ResponseResult.success(pointService.submitAudit(request));
    }

    @ApiOperation("选址审批设置")
    @PostMapping("/auditSetting")
    public ResponseResult<Integer> auditSetting(@RequestBody AuditSettingRequest request) {
        return ResponseResult.success(pointService.auditSetting(request));
    }

    @ApiOperation("获取选址审批设置")
    @GetMapping("/getAuditSetting")
    public ResponseResult<AuditSettingVO> getAuditSetting() {
        return ResponseResult.success(pointService.getAuditSetting());
    }

    @ApiOperation("获取催办用户列表")
    @GetMapping("/getTodoUserList")
    public ResponseResult<List<String>> getTodoUserList(@RequestParam("pointId")Long pointId) {
        return ResponseResult.success(pointService.getTodoUserList(pointId));
    }

    @ApiOperation("营运人员审批")
    @PostMapping("/operationUserAudit")
    public ResponseResult<Integer> operationUserAudit(@RequestBody @Validated OperationAuditRequest request) {
        return ResponseResult.success(pointService.operationUserAudit(CurrentUserHolder.getUserId(), request));
    }

    @ApiOperation("审批(排除第二级审批)")
    @PostMapping("/audit")
    public ResponseResult<Integer> audit(@RequestBody PointAuditRequest request) {
        return ResponseResult.success(pointService.audit(CurrentUserHolder.getUserId(), request));
    }

    @ApiOperation("铺位转让")
    @PostMapping("/turnDevelopmentManager")
    public ResponseResult<Integer> turnDevelopmentManager(@RequestBody @Validated TurnDevelopmentManagerRequest request) {
        return ResponseResult.success(pointService.turnDevelopmentManager(request));
    }

    @ApiOperation("获取我负责的加盟商列表")
    @PostMapping("/getLinePage")
    public ResponseResult<PageInfo<LinePointBaseInfoVO>> getLinePage(@RequestBody PointLinePageRequest request) {
        request.setDevelopmentManager(CurrentUserHolder.getUserId());
        return ResponseResult.success(pointService.getLinePage(request));
    }

    @ApiOperation("获取单个加盟商选址数据")
    @GetMapping("/getLineInfo")
    public ResponseResult<LinePointBaseInfoVO> getLineInfo(@RequestParam("lineId") Long lineId) {
        return ResponseResult.success(pointService.getLineInfo(lineId));
    }

    @ApiOperation("首页我的数据")
    @GetMapping("/getMyData")
    public ResponseResult<PointHomePageDataVO> getMyPointData() {
        return ResponseResult.success(pointService.getMyPointData(CurrentUserHolder.getUserId()));
    }

    @ApiOperation("我的铺位-已入库/暂未入库")
    @PostMapping("/getMyPointPage")
    public ResponseResult<PageInfo<PointPageVO>> getMyPointPage(@RequestBody @Validated PointPageRequest request) {
        request.setDevelopmentManager(CurrentUserHolder.getUserId());
        return ResponseResult.success(pointService.getMyPointPage(request));
    }

    @ApiOperation("全部铺位")
    @PostMapping("/getTeamPointPage")
    public ResponseResult<PageInfo<PointPageVO>> getTeamPointPage(@RequestBody @Validated AllPointPageRequest request) {
        request.setCurUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(pointService.getTeamPointPage(request));
    }

    @ApiOperation("获取单个铺位审批记录")
    @GetMapping("/getAuditRecord")
    public ResponseResult<List<PointAuditRecordVO>> getPointAllAuditRecord(@RequestParam("pointId")Long pointId) {
        return ResponseResult.success(pointService.getPointAllAuditRecord(pointId));
    }

    @ApiOperation("获取加盟商的推荐铺位列表")
    @GetMapping("/getLineRecommendPointList")
    public ResponseResult<List<PointRecommendPageVO>> getLineRecommendPointList(@RequestParam("lineId")Long lineId) {
        return ResponseResult.success(pointService.getLineRecommendPointList(lineId));
    }

    @ApiOperation("选址人员获取可推荐铺位列表")
    @PostMapping("/getRecommendPointList")
    public ResponseResult<PageInfo<PointPageVO>> getRecommendPointList(@RequestBody @Validated RecommendPointPageRequest request) {
        request.setDevelopmentManager(CurrentUserHolder.getUserId());
        return ResponseResult.success(pointService.getRecommendPointList(request));
    }

    @ApiOperation("加盟商详情推送铺位")
    @PostMapping("/lineRecommendPoint")
    public ResponseResult<Integer> lineRecommendPoint(@RequestBody @Validated LineRecommendPointRequest request) {
        request.setDevelopmentManager(CurrentUserHolder.getUserId());
        return ResponseResult.success(pointService.lineRecommendPoint(request));
    }

    @ApiOperation("铺位详情推送加盟商")
    @PostMapping("/pointRecommendLine")
    public ResponseResult<Integer> pointRecommendLine(@RequestBody @Validated PointRecommendLineRequest request) {
        request.setDevelopmentManager(CurrentUserHolder.getUserId());
        return ResponseResult.success(pointService.pointRecommendLine(request));
    }

    @ApiOperation("选址人员转让加盟商")
    @PostMapping("/turnLine")
    public ResponseResult<Integer> turnLine(@RequestBody @Validated TurnLineRequest request) {
        return ResponseResult.success(pointService.turnLine(request));
    }

    @ApiOperation("修改意向开店数量")
    @PostMapping("/updateWantShopNum")
    public ResponseResult<Integer> updateWantShopNum(@RequestBody @Validated UpdateWantShopNumRequest request) {
        return ResponseResult.success(pointService.updateWantShopNum(request));
    }

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

    @ApiOperation("获取待办列表")
    @PostMapping("/getTodoList")
    public ResponseResult<PageInfo<PointPageVO>> getTodoList(@RequestBody PointTodoPageRequest request) {
        request.setDevelopmentManager(CurrentUserHolder.getUserId());
        return ResponseResult.success(pointService.getTodoList(request));
    }

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

    @ApiOperation("租赁合同审核")
    @PostMapping("/auditRentContract")
    public ResponseResult<Integer> auditRentContract(@RequestBody @Validated AuditRentContractRequest request) {
        request.setOperateUserId(CurrentUserHolder.getUserId());
        request.setOperateUserName(CurrentUserHolder.getUser().getName());
        return ResponseResult.success(pointService.auditRentContract(request));
    }

    @ApiOperation("获取推荐给加盟商的铺位")
    @PostMapping("/getLineRecommendPointPage")
    public ResponseResult<PageInfo<MiniPointPageVO>> getLineRecommendPointPage(@RequestBody MiniPointPageRequest request) {
        return ResponseResult.success(pointService.getLineRecommendPointPage(request));
    }

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

}
