package com.zt.plat.module.base.api.materialgradeext;

import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.base.api.materialgradeext.dto.MaterialGradeExtPageReqDTO;
import com.zt.plat.module.base.api.materialgradeext.dto.MaterialGradeExtRespDTO;
import com.zt.plat.module.base.api.materialgradeext.dto.MaterialGradeExtSaveReqDTO;
import com.zt.plat.module.base.controller.admin.materialgradeext.vo.MaterialGradeExtPageReqVO;
import com.zt.plat.module.base.controller.admin.materialgradeext.vo.MaterialGradeExtRespVO;
import com.zt.plat.module.base.controller.admin.materialgradeext.vo.MaterialGradeExtSaveReqVO;
import com.zt.plat.module.base.service.materialgradeext.MaterialGradeExtService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.zt.plat.framework.common.pojo.CommonResult.success;

@RestController
@Validated
public class MaterialGradeExtApiImpl implements MaterialGradeExtApi {

    @Resource
    private MaterialGradeExtService materialGradeExtService;

    @Override
    public CommonResult<MaterialGradeExtRespDTO> create(MaterialGradeExtSaveReqDTO reqDTO) {
        MaterialGradeExtRespVO respVO = materialGradeExtService.create(BeanUtils.toBean(reqDTO, MaterialGradeExtSaveReqVO.class));
        return success(BeanUtils.toBean(respVO, MaterialGradeExtRespDTO.class));
    }

    @Override
    public CommonResult<Boolean> update(MaterialGradeExtSaveReqDTO reqDTO) {
        materialGradeExtService.update(BeanUtils.toBean(reqDTO, MaterialGradeExtSaveReqVO.class));
        return success(true);
    }

    @Override
    public CommonResult<Boolean> delete(Long id) {
        materialGradeExtService.delete(id);
        return success(true);
    }

    @Override
    public CommonResult<Boolean> deleteList(List<Long> ids) {
        materialGradeExtService.deleteByIds(ids);
        return success(true);
    }

    @Override
    public CommonResult<MaterialGradeExtRespDTO> get(Long id) {
        MaterialGradeExtRespVO respVO = materialGradeExtService.get(id);
        return success(BeanUtils.toBean(respVO, MaterialGradeExtRespDTO.class));
    }

    @Override
    public CommonResult<PageResult<MaterialGradeExtRespDTO>> getPage(@RequestBody MaterialGradeExtPageReqDTO pageReqDTO) {
        MaterialGradeExtPageReqVO pageReqVO = BeanUtils.toBean(pageReqDTO, MaterialGradeExtPageReqVO.class);
        PageResult<MaterialGradeExtRespVO> pageResult = materialGradeExtService.getPage(pageReqVO);
        PageResult<MaterialGradeExtRespDTO> dtoResult = BeanUtils.toBean(pageResult, MaterialGradeExtRespDTO.class);
        return success(dtoResult);
    }
}