package com.yc.ship.module.product.controller.admin.voyagestockdistributeNew;

import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.collection.CollectionUtils;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.product.controller.admin.voyagestockdistribute.vo.VoyageStockDistributeReqVO;
import com.yc.ship.module.product.controller.admin.voyagestockdistribute.vo.VoyageStockDistributeRespVO;
import com.yc.ship.module.product.controller.admin.voyagestockdistributeNew.vo.*;
import com.yc.ship.module.product.dal.dataobject.voyagestockdistribute.VoyageStockDistributeDO;
import com.yc.ship.module.product.service.voyagestockdistribute.VoyageStockDistributeNewService;
import com.yc.ship.module.resource.api.room.dto.RoomRespDTO;
import com.yc.ship.module.resource.dal.dataobject.roommodel.ResourceRoomModelDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

import static com.yc.ship.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 航次库存分配")
@RestController
@RequestMapping("/product/voyage-stock-distribute-new")
@Validated
public class VoyageStockDistributeNewController {

    @Resource
    private VoyageStockDistributeNewService voyageStockDistributeNewService;


    @Operation(summary = "创建航次库存分配")
    @PostMapping("/create/{voyageId}/{type}")
    @PreAuthorize("@ss.hasPermission('product:voyage-stock-distribute-new:create')")
    public CommonResult<Boolean> createVoyageStockDistribute(@PathVariable("voyageId") Long voyageId,@PathVariable("type") Integer type,@Valid @RequestBody List<VoyageStockDistributeNewSaveReqVO> createReqVO) {
        voyageStockDistributeNewService.createVoyageStockDistributeNew(voyageId,type,createReqVO);
        return success(true);
    }

    @Operation(summary = "获取航次库存分配")
    @GetMapping("/getByVoyageId")
    public CommonResult<List<VoyageStockDistributeNewRespVO>> getByVoyageId(@RequestParam("voyageId") Long voyageId, @RequestParam("type") Integer type) {
        List<VoyageStockDistributeNewRespVO> list = voyageStockDistributeNewService.getByVoyageId(voyageId, type);
        return success(list);
    }

    @GetMapping("/getRoomList")
    @Operation(summary = "获取航次库存分配房间列表, 运营端调用")
    public CommonResult<List<RoomRespDTO>> getRoomList(@RequestParam("voyageId") Long voyageId, @RequestParam("shipId") Long shipId) {
        List<RoomRespDTO> list = voyageStockDistributeNewService.getRoomList(voyageId, shipId);
        return success(list);
    }

    @GetMapping("/getDistributorRoomList")
    @Operation(summary = "获取航次库存分配房间列表, 分销商端调用")
    public CommonResult<List<RoomRespDTO>> getDistributorRoomList(@RequestParam("voyageId") Long voyageId,
                                                                  @RequestParam("shipId") Long shipId,
                                                                  @RequestParam("distributorId") Long distributorId) {
        List<RoomRespDTO> list = voyageStockDistributeNewService.getDistributorRoomList(voyageId, shipId, distributorId);
        return success(list);
    }

    @PostMapping("/getCanSelectRoomList")
    @Operation(summary = "分销商门店下单时获得可以选择的房间号")
    public CommonResult<List<RoomRespDTO>> getCanSelectRoomList(@RequestBody QueryCanSelectRoomListNewReqVO reqVO) {
        List<RoomRespDTO> list = voyageStockDistributeNewService.getCanSelectRoomList(reqVO);
        return success(list);
    }

    @GetMapping("/page")
    @Operation(summary = "获取分销商或门店航次库存分页")
    public CommonResult<PageResult<VoyageStockDistributeNewPageRespVO>> getVoyageStockDistributePage(@Validated VoyageStockDistributeNewPageReqVO reqVO) {
        PageResult<VoyageStockDistributeNewPageRespVO> page = voyageStockDistributeNewService.getPage(reqVO);
        return success(page);
    }

    @GetMapping("/detail")
    @Operation(summary = "获取航次库存分配详情")
    public CommonResult<List<VoyageStockDistributeNewRespVO>> getDetail(@Valid VoyageStockDistributeNewDetailReqVO reqVO) {
        List<VoyageStockDistributeNewRespVO> list = voyageStockDistributeNewService.getDetail(reqVO);
        return success(list);
    }


}