package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.PartnerUserHolder;
import com.cool.store.enums.PlatformBuildEnum;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.request.PlatformBuildAuditRequest;
import com.cool.store.request.platformBuildListRequest;
import com.cool.store.response.AuditInfoResponse;
import com.cool.store.response.PlatformBuildListResponse;
import com.cool.store.response.PlatformBuildResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.OperationLogService;
import com.cool.store.service.PlatformBuildService;
import com.cool.store.vo.PlatformBuildInfoVO;
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.ArrayList;
import java.util.List;

/**
 * @Author: WangShuo
 * @Date: 2024/10/10/下午3:58
 * @Version 1.0
 * @注释:
 */
@Api("pc平台建店")
@RestController
@RequestMapping("/pc/platformBuild")
public class PCPlatformBuildController {

    @Resource
    private OperationLogService operationLogService;
    @Resource
    private PlatformBuildService platformBuildService;

    @ApiOperation("平台建店列表")
    @PostMapping("/platformBuildList")
    public ResponseResult<PageInfo<PlatformBuildListResponse>> platformBuildList(@RequestBody platformBuildListRequest request) {
        request.setOperateUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(platformBuildService.platformBuildList(request));
    }
    @ApiOperation("根据type获取平台建店详情:1-抖音，2-快手，3-美团团购，4-饿了么，5-美团外卖")
    @GetMapping("/get")
    public ResponseResult<PlatformBuildResponse> get(@RequestParam("shopId") Long shopId,@RequestParam("type") Integer type) {
     return ResponseResult.success(platformBuildService.get(shopId, type));
    }
    @ApiOperation("获取平台建店左侧小窗详情")
    @GetMapping("/getPlatformBuildInfo")
    public ResponseResult<PlatformBuildInfoVO> getPlatformBuildInfo(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(platformBuildService.getPlatformBuildInfo(shopId));
    }
    @ApiOperation("一级审批")
    @PostMapping("/firstAudit")
    public ResponseResult<Integer> firstAudit(@RequestBody @Validated PlatformBuildAuditRequest request) {
        request.setOperateUserId(CurrentUserHolder.getUserId());
        request.setOperateUserName(CurrentUserHolder.getUser().getName());
        return ResponseResult.success(platformBuildService.firstAudit(request));
    }
    @ApiOperation("二级级审批  美团外卖&饿了么")
    @PostMapping("/secondAudit")
    public ResponseResult<Integer> secondAudit(@RequestBody @Validated PlatformBuildAuditRequest request) {
        request.setOperateUserId(CurrentUserHolder.getUserId());
        request.setOperateUserName(CurrentUserHolder.getUser().getName());
        return ResponseResult.success(platformBuildService.secondAudit(request));
    }

    @ApiOperation("根据type获取平台建店审批记录:1-抖音，2-快手，3-美团团购，4-饿了么，5-美团外卖")
    @GetMapping("/getAuditInfo")
    public ResponseResult<List<AuditInfoResponse>> getAuditInfo(@RequestParam("shopId") Long shopId, @RequestParam("type") Integer type) {
        List<Integer> shopSubStageList = new ArrayList<>();
        if (type.equals(PlatformBuildEnum.DOU_YIN.getCode())) {
            shopSubStageList.add(ShopSubStageEnum.SHOP_STAGE_18.getShopSubStage());
        }else if (type.equals(PlatformBuildEnum.KUAI_SHOU.getCode())) {
            shopSubStageList.add(ShopSubStageEnum.SHOP_STAGE_22.getShopSubStage());
        }else if (type.equals(PlatformBuildEnum.MEI_TUAN_TUAN_GOU.getCode())) {
            shopSubStageList.add(ShopSubStageEnum.SHOP_STAGE_20.getShopSubStage());
        }else if (type.equals(PlatformBuildEnum.E_LE_ME.getCode())) {
            shopSubStageList.add(ShopSubStageEnum.SHOP_STAGE_21.getShopSubStage());
        }else if (type.equals(PlatformBuildEnum.MEI_TUAN_WAI_MAI.getCode())) {
            shopSubStageList.add(ShopSubStageEnum.SHOP_STAGE_19.getShopSubStage());
        }
        return ResponseResult.success(operationLogService.getAuditInfo(shopId, shopSubStageList));
    }

}
