package com.fzm.mall.server.admin.opration.controller;


import com.fzm.mall.server.admin.annotation.AdminLog;
import com.fzm.mall.server.admin.enums.log.OperateModuleEnum;
import com.fzm.mall.server.admin.enums.log.OperateTypeEnum;
import com.fzm.mall.server.admin.opration.entity.dto.FloorGoodsDTO;
import com.fzm.mall.server.admin.opration.entity.dto.FloorGoodsSaveDTO;
import com.fzm.mall.server.admin.opration.service.IFloorGoodsService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 运营中心-首页楼层 前端控制器
 * </p>
 *
 * @author fzm
 * @since 2021-03-23
 */
@Api(tags = "运营中心")
@RestController
@RequestMapping("/floor-goods/floorGoodsPermission")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FloorGoodsController {

    private final IFloorGoodsService floorGoodsService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "运营中心-楼层-商品-新增")
    @ApiOperationSupport(order = 1)
    @AdminLog(description = "运营中心-楼层-商品-新增", module = OperateModuleEnum.OPERATE_CENTER, opType = OperateTypeEnum.ADD)
    @PostMapping("/save")
    public ResponseVO save(@RequestBody @Valid FloorGoodsSaveDTO floorGoodsSaveDTO) {
        floorGoodsService.save(floorGoodsSaveDTO);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "运营中心-楼层-商品-删除")
    @ApiOperationSupport(order = 3)
    @AdminLog(description = "运营中心-楼层-商品-删除", module = OperateModuleEnum.OPERATE_CENTER, opType = OperateTypeEnum.DELETE)
    @DeleteMapping("/delete/{operationFloorId}/{goodsId}")
    public ResponseVO delete(
            @ApiParam(value = "楼层-楼层编号", required = true) @PathVariable(value = "operationFloorId") String operationFloorId,
            @ApiParam(value = "楼层-商品编号", required = true) @PathVariable(value = "goodsId") String goodsId) {
        floorGoodsService.delete(operationFloorId, goodsId);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "运营中心-楼层-商品-列表查询")
    @ApiOperationSupport(order = 5)
    @GetMapping("/list")
    public ResponseVO list(@ApiParam(value = "楼层-楼层编号", required = true) @RequestParam String operationFloorId) {

        List<FloorGoodsDTO> result = floorGoodsService.listAll(operationFloorId);
        return resFac.getSuccessResponseWithData(result);
    }
}
