
package com.tmerclub.cloud.product.controller.multishop;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.BeanUtil;
import com.tmerclub.cloud.product.dto.StockChangeReasonStatusDTO;
import com.tmerclub.cloud.product.model.StockChangeReasonStatus;
import com.tmerclub.cloud.product.service.StockChangeReasonStatusService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 出入库原因状态
 *
 * @author lhd
 * @date 2022-06-22 17:14:22
 */
@RestController("multishopStockChangeReasonStatusController")
@RequestMapping("/m/stock_change_reason_status")
@Tag(name = "出入库原因状态")
public class StockChangeReasonStatusController {

    @Autowired
    private StockChangeReasonStatusService stockChangeReasonStatusService;


    @GetMapping("/page")
    @Operation(summary = "获取出入库原因状态列表", description = "分页获取出入库原因状态列表")
    public ServerResponseEntity<PageVO<StockChangeReasonStatus>> page(@Valid PageDTO pageDTO) {
        PageVO<StockChangeReasonStatus> stockChangeReasonStatusPage = stockChangeReasonStatusService.page(pageDTO);
        return ServerResponseEntity.success(stockChangeReasonStatusPage);
    }

    @GetMapping
    @Operation(summary = "获取出入库原因状态", description = "根据stockChangeReasonStatusId获取出入库原因状态")
    public ServerResponseEntity<StockChangeReasonStatus> getByStockChangeReasonStatusId(@RequestParam Long stockChangeReasonStatusId) {
        return ServerResponseEntity.success(stockChangeReasonStatusService.getByStockChangeReasonStatusId(stockChangeReasonStatusId));
    }

    @PostMapping
    @Operation(summary = "保存出入库原因状态", description = "保存出入库原因状态")
    public ServerResponseEntity<Void> save(@Valid @RequestBody StockChangeReasonStatusDTO stockChangeReasonStatusDTO) {
        StockChangeReasonStatus stockChangeReasonStatus = BeanUtil.map(stockChangeReasonStatusDTO, StockChangeReasonStatus.class);
        stockChangeReasonStatus.setStockChangeReasonStatusId(null);
        stockChangeReasonStatusService.save(stockChangeReasonStatus);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新出入库原因状态", description = "更新出入库原因状态")
    public ServerResponseEntity<Void> update(@Valid @RequestBody StockChangeReasonStatusDTO stockChangeReasonStatusDTO) {
        StockChangeReasonStatus stockChangeReasonStatus = BeanUtil.map(stockChangeReasonStatusDTO, StockChangeReasonStatus.class);
        stockChangeReasonStatusService.update(stockChangeReasonStatus);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除出入库原因状态", description = "根据出入库原因状态id删除出入库原因状态")
    public ServerResponseEntity<Void> delete(@RequestParam Long stockChangeReasonStatusId) {
        stockChangeReasonStatusService.deleteById(stockChangeReasonStatusId);
        return ServerResponseEntity.success();
    }
}
