
package com.tmerclub.cloud.distribution.controller.platform;

import com.tmerclub.cloud.api.distribution.vo.DistributionSpuVO;
import com.tmerclub.cloud.api.platform.dto.OfflineHandleEventDTO;
import com.tmerclub.cloud.api.platform.vo.OfflineHandleEventVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.distribution.service.DistributionSpuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分销商品关联信息
 *
 * @author cl
 * @date 2021-08-09 14:14:07
 */
@RestController("platformDistributionSpuController")
@RequestMapping("/p/distributionSpu")
@Tag(name = "platform-分销商品关联信息")
public class DistributionSpuController {

    @Autowired
    private DistributionSpuService distributionSpuService;

    @GetMapping
    @Operation(summary = "获取分销商品关联信息", description = "根据distributionSpuId获取分销商品关联信息")
    public ServerResponseEntity<DistributionSpuVO> getByDistributionSpuId(@RequestParam Long distributionSpuId) {
        return ServerResponseEntity.success(distributionSpuService.getByDistributionSpuId(distributionSpuId));
    }

    @PostMapping("/offline")
    @Operation(summary = "下线分销商品", description = "下线分销商品")
    public ServerResponseEntity<Void> offline(@RequestBody OfflineHandleEventDTO offlineHandleEventDTO) {
        distributionSpuService.offline(offlineHandleEventDTO);
        return ServerResponseEntity.success();
    }

    @PostMapping("/audit")
    @Operation(summary = "审核分销商品", description = "审核分销商品")
    public ServerResponseEntity<Void> audit(@RequestBody OfflineHandleEventDTO offlineHandleEventDTO) {
        distributionSpuService.audit(offlineHandleEventDTO);
        return ServerResponseEntity.success();
    }

    @GetMapping("/getOfflineHandleEvent")
    @Operation(summary = "获取分销商品下线信息", description = "获取分销商品下线信息")
    public ServerResponseEntity<OfflineHandleEventVO> getOfflineHandleEvent(@RequestParam("distributionSpuId") Long distributionSpuId) {
        return ServerResponseEntity.success(distributionSpuService.getOfflineHandleEvent(distributionSpuId));
    }

    @DeleteMapping
    @Operation(summary = "删除分销商品关联信息", description = "根据分销商品关联信息id删除分销商品关联信息")
    public ServerResponseEntity<Void> delete(@RequestParam Long distributionSpuId) {
        distributionSpuService.deleteByIdAndShopId(distributionSpuId, null);
        return ServerResponseEntity.success();
    }

}
