
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.StockChangeReasonLangDTO;
import com.tmerclub.cloud.product.model.StockChangeReasonLang;
import com.tmerclub.cloud.product.service.StockChangeReasonLangService;
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("multishopStockChangeReasonLangController")
@RequestMapping("/m/stock_change_reason_lang")
@Tag(name = "出入库原因-国际化")
public class StockChangeReasonLangController {

    @Autowired
    private StockChangeReasonLangService stockChangeReasonLangService;


    @GetMapping("/page")
    @Operation(summary = "获取出入库原因-国际化列表", description = "分页获取出入库原因-国际化列表")
    public ServerResponseEntity<PageVO<StockChangeReasonLang>> page(@Valid PageDTO pageDTO) {
        PageVO<StockChangeReasonLang> stockChangeReasonLangPage = stockChangeReasonLangService.page(pageDTO);
        return ServerResponseEntity.success(stockChangeReasonLangPage);
    }

    @GetMapping
    @Operation(summary = "获取出入库原因-国际化", description = "根据stockChangeReasonId获取出入库原因-国际化")
    public ServerResponseEntity<StockChangeReasonLang> getByStockChangeReasonId(@RequestParam Long stockChangeReasonId) {
        return ServerResponseEntity.success(stockChangeReasonLangService.getByStockChangeReasonId(stockChangeReasonId));
    }

    @PostMapping
    @Operation(summary = "保存出入库原因-国际化", description = "保存出入库原因-国际化")
    public ServerResponseEntity<Void> save(@Valid @RequestBody StockChangeReasonLangDTO stockChangeReasonLangDTO) {
        StockChangeReasonLang stockChangeReasonLang = BeanUtil.map(stockChangeReasonLangDTO, StockChangeReasonLang.class);
        stockChangeReasonLang.setStockChangeReasonId(null);
        stockChangeReasonLangService.save(stockChangeReasonLang);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新出入库原因-国际化", description = "更新出入库原因-国际化")
    public ServerResponseEntity<Void> update(@Valid @RequestBody StockChangeReasonLangDTO stockChangeReasonLangDTO) {
        StockChangeReasonLang stockChangeReasonLang = BeanUtil.map(stockChangeReasonLangDTO, StockChangeReasonLang.class);
        stockChangeReasonLangService.update(stockChangeReasonLang);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除出入库原因-国际化", description = "根据出入库原因-国际化id删除出入库原因-国际化")
    public ServerResponseEntity<Void> delete(@RequestParam Long stockChangeReasonId) {
        stockChangeReasonLangService.deleteById(stockChangeReasonId);
        return ServerResponseEntity.success();
    }
}
