package com.cool.store.controller.webb;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.dao.ShopStageInfoDAO;
import com.cool.store.dto.openPreparation.FirstOrderDTO;
import com.cool.store.entity.FirstOrderDO;
import com.cool.store.entity.ShopInfoDO;
import com.cool.store.entity.ShopStageInfoDO;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.request.FirstOrderRequest;
import com.cool.store.request.OpeningOperationPlanAuditRequest;
import com.cool.store.request.OpeningOperationPlanRequest;
import com.cool.store.request.PlanListRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.*;
import com.cool.store.vo.OpeningOperationPlanListVO;
import com.cool.store.vo.OpeningOperationPlanVO;
import com.cool.store.vo.shop.ShopStageInfoVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @Auther: WangShuo
 * @Date: 2024/04/25/下午6:35
 * @Version 1.0
 * @注释:
 */
@RestController
@RequestMapping("/pc/openPreparation")
@Api(tags = "pc开业筹备")
@Slf4j
public class PCOpenPreparationController {

    @Resource
    private FirstOrderService firstOrderService;
    @Resource
    private OpeningOperationPlanService openingOperationPlanService;
    @Resource
    private AuditOpeningOperationPlanService auditOpeningOperationPlanService;
    @ApiOperation("刷新订货金状态")
    @GetMapping("/flush")
    public ResponseResult<Boolean> flush(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(openingOperationPlanService.flush(shopId));
    }
    @ApiOperation("获取鲜丰订货金状态")
    @GetMapping("/getStatus")
    public ResponseResult<Boolean> getStatus(@RequestParam("shopId") Long shopId) {

        return ResponseResult.success(openingOperationPlanService.getStatus(shopId));
    }
    @PostMapping("/openingOperationPlan/submit")
    @ApiOperation("提交开业运营方案")
    public ResponseResult submitPlan(@RequestBody OpeningOperationPlanRequest request) {
        return ResponseResult.success(openingOperationPlanService.savePlan(request,CurrentUserHolder.getUser()));
    }

    @GetMapping("/openingOperationPlan/getPlan")
    @ApiOperation("查询开业运营方案")
    public ResponseResult<OpeningOperationPlanVO> getPlan(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(openingOperationPlanService.getPlanByShopId(shopId));
    }
    @PostMapping("/openingOperationPlan/planList")
    @ApiOperation("查询运营方案列表")
    public ResponseResult<PageInfo<OpeningOperationPlanListVO>> planList(@RequestBody PlanListRequest request) {
        request.setCurUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(openingOperationPlanService.getPlanListPage(request));
    }
    @PostMapping("/openingOperationPlan/audit")
    @ApiOperation("审核运营方案")
    public ResponseResult auditPlan(@RequestBody OpeningOperationPlanAuditRequest request) {
        return ResponseResult.success(auditOpeningOperationPlanService.auditPlan(request,CurrentUserHolder.getUser()));
    }

    @GetMapping("/firstOrder/get")
    @ApiOperation("查询订货金")
    public ResponseResult<FirstOrderDTO> get(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(firstOrderService.getOrder(shopId));
    }

    @PostMapping("/firstOrder/submit")
    @ApiOperation("提交订货金")
    public ResponseResult submit(@RequestBody FirstOrderRequest request) {
        return ResponseResult.success(firstOrderService.saveOrder(request,CurrentUserHolder.getUser()));

    }
}
