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

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.SpuConsignmentChangeDTO;
import com.tmerclub.cloud.product.model.SpuConsignmentChange;
import com.tmerclub.cloud.product.service.SpuConsignmentChangeService;
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 tmerclub
 * @date 2022-08-11 22:21:10
 */
@RestController("multishopSpuConsignmentChangeController")
@RequestMapping("/m/spu_consignment_change")
@Tag(name = "商家代销商品基本信息相对于供应商品是否改变")
public class SpuConsignmentChangeController {

    @Autowired
    private SpuConsignmentChangeService spuConsignmentChangeService;


    @GetMapping("/page")
    @Operation(summary = "获取商家代销商品基本信息相对于供应商品是否改变列表", description = "分页获取商家代销商品基本信息相对于供应商品是否改变列表")
    public ServerResponseEntity<PageVO<SpuConsignmentChange>> page(@Valid PageDTO pageDTO) {
        PageVO<SpuConsignmentChange> spuConsignmentChangePage = spuConsignmentChangeService.page(pageDTO);
        return ServerResponseEntity.success(spuConsignmentChangePage);
    }

    @GetMapping
    @Operation(summary = "获取商家代销商品基本信息相对于供应商品是否改变", description = "根据consignmentChangeId获取商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<SpuConsignmentChange> getByConsignmentChangeId(@RequestParam Long consignmentChangeId) {
        return ServerResponseEntity.success(spuConsignmentChangeService.getByConsignmentChangeId(consignmentChangeId));
    }

    @PostMapping
    @Operation(summary = "保存商家代销商品基本信息相对于供应商品是否改变", description = "保存商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<Void> save(@Valid @RequestBody SpuConsignmentChangeDTO spuConsignmentChangeDTO) {
        SpuConsignmentChange spuConsignmentChange = BeanUtil.map(spuConsignmentChangeDTO, SpuConsignmentChange.class);
        spuConsignmentChange.setConsignmentChangeId(null);
        spuConsignmentChangeService.save(spuConsignmentChange);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新商家代销商品基本信息相对于供应商品是否改变", description = "更新商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<Void> update(@Valid @RequestBody SpuConsignmentChangeDTO spuConsignmentChangeDTO) {
        SpuConsignmentChange spuConsignmentChange = BeanUtil.map(spuConsignmentChangeDTO, SpuConsignmentChange.class);
        spuConsignmentChangeService.update(spuConsignmentChange);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除商家代销商品基本信息相对于供应商品是否改变", description = "根据商家代销商品基本信息相对于供应商品是否改变id删除商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<Void> delete(@RequestParam Long consignmentChangeId) {
        spuConsignmentChangeService.deleteById(consignmentChangeId);
        return ServerResponseEntity.success();
    }
}
