package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.dto.XgjOrganizationDTO;
import com.cool.store.enums.OrderSysTypeEnum;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.request.AuditRequest;
import com.cool.store.request.OrderSysInfoRequest;
import com.cool.store.response.AuditInfoResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.OperationLogService;
import com.cool.store.service.OrderSysInfoService;
import com.cool.store.service.PushService;
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.Collections;
import java.util.List;

/**
 * @Author: WangShuo
 * @Date: 2025/04/06/17:39
 * @Version 1.0
 * @注释:
 */
@Api("pc订货信息&总部订货收款账户")
@RestController
@RequestMapping("/pc/orderInfo")
public class PCOrderSysInfoController {

    @Resource
    private OrderSysInfoService orderSysInfoService;
    @Resource
    private PushService pushService;
    @Resource
    private OperationLogService operationLogService;

    @PostMapping("/submitOrderInfo")
    @ApiOperation("物流提交订货信息")
    public ResponseResult<Integer> submitOrderInfo(@RequestBody @Validated OrderSysInfoRequest request){
        request.setType(OrderSysTypeEnum.ORDER_SYS_TYPE_1.getType());
        return ResponseResult.success(orderSysInfoService.updateByShopId(request, CurrentUserHolder.getUser()));
    }

    @PostMapping("/submitReceiving")
    @ApiOperation("财务提交总部订货收款账户")
    public ResponseResult<Integer> submitReceiving(@RequestBody @Validated OrderSysInfoRequest request){
        request.setType(OrderSysTypeEnum.ORDER_SYS_TYPE_2.getType());
        return ResponseResult.success(orderSysInfoService.updateByShopId(request, CurrentUserHolder.getUser()));
    }

    @GetMapping("/getXgjOrganization")
    @ApiOperation("获取新管家组织架构")
    public ResponseResult<List<XgjOrganizationDTO>> getXgjOrganization(@RequestParam(value = "parentId", required = true,defaultValue = "0") String parentId) {
        return ResponseResult.success(pushService.getXgjOrganization(parentId));
    }

    @PostMapping("/audit")
    @ApiOperation("审核")
    public ResponseResult<Integer> audit(@RequestBody @Validated AuditRequest request){
        return ResponseResult.success(orderSysInfoService.audit(request, CurrentUserHolder.getUser()));
    }
    @GetMapping("/auditInfo")
    @ApiOperation("获取审批流")
    public ResponseResult<List<AuditInfoResponse>> auditInfo(@RequestParam("shopId") Long shopId){

        return ResponseResult.success(operationLogService.getAuditInfo(shopId, Collections.singletonList(ShopSubStageEnum.SHOP_STAGE_15.getShopSubStage())));
    }

}
