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

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.departmentmaterial.dto.DepartmentMaterialPageReqDTO;
import com.zt.plat.module.base.api.departmentmaterial.dto.DepartmentMaterialRespDTO;
import com.zt.plat.module.base.api.departmentmaterial.dto.DepartmentMaterialSaveReqDTO;
import com.zt.plat.module.base.controller.admin.departmentmaterial.vo.DepartmentMaterialPageReqVO;
import com.zt.plat.module.base.controller.admin.departmentmaterial.vo.DepartmentMaterialRespVO;
import com.zt.plat.module.base.controller.admin.departmentmaterial.vo.DepartmentMaterialSaveReqVO;
import com.zt.plat.module.base.service.departmentmaterial.DepartmentMaterialService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
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 DepartmentMaterialApiImpl implements DepartmentMaterialApi {

    @Resource
    private DepartmentMaterialService departmentMaterialService;

    @Override
    public CommonResult<DepartmentMaterialRespDTO> createDepartmentMaterial(DepartmentMaterialSaveReqDTO createReqDTO) {
        DepartmentMaterialRespVO respVO = departmentMaterialService.createDepartmentMaterial(BeanUtils.toBean(createReqDTO, DepartmentMaterialSaveReqVO.class));
        return success(BeanUtils.toBean(respVO, DepartmentMaterialRespDTO.class));
    }

    @Override
    public CommonResult<Boolean> updateDepartmentMaterial(DepartmentMaterialSaveReqDTO updateReqDTO) {
        departmentMaterialService.updateDepartmentMaterial(BeanUtils.toBean(updateReqDTO, DepartmentMaterialSaveReqVO.class));
        return success(true);
    }

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

    @Override
    public CommonResult<Boolean> deleteDepartmentMaterialList(List<Long> ids) {
        departmentMaterialService.deleteDepartmentMaterialListByIds(ids);
        return success(true);
    }

    @Override
    public CommonResult<DepartmentMaterialRespDTO> getDepartmentMaterial(Long id) {
        DepartmentMaterialRespVO respVO = departmentMaterialService.getDepartmentMaterial(id);
        return success(BeanUtils.toBean(respVO, DepartmentMaterialRespDTO.class));
    }

    @Override
    public CommonResult<PageResult<DepartmentMaterialRespDTO>> getDepartmentMaterialPage(DepartmentMaterialPageReqDTO pageReqDTO) {
        DepartmentMaterialPageReqVO pageReqVO = BeanUtils.toBean(pageReqDTO, DepartmentMaterialPageReqVO.class);
        PageResult<DepartmentMaterialRespVO> pageResult = departmentMaterialService.getDepartmentMaterialPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DepartmentMaterialRespDTO.class));
    }
}
