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

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.materialinfomation.dto.MaterialInfomationPageReqDTO;
import com.zt.plat.module.base.api.materialinfomation.dto.MaterialInfomationRespDTO;
import com.zt.plat.module.base.api.materialinfomation.dto.MaterialInfomationSaveReqDTO;
import com.zt.plat.module.base.api.materialinfomation.dto.MaterialInfomationSimplePageReqDTO;
import com.zt.plat.module.base.api.materialinfomation.dto.MaterialInfomationSimpleRespDTO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationPageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationRespVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSaveReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimplePageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimpleRespVO;
import com.zt.plat.module.base.service.base.MaterialInfomationService;
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 MaterialInfomationApiImpl implements MaterialInfomationApi {

    @Resource
    private MaterialInfomationService materialInfomationService;

/*    @Override
    public CommonResult<MaterialInfomationRespDTO> createMaterialInfomation(MaterialInfomationSaveReqDTO createReqDTO) {
        MaterialInfomationRespVO respVO = materialInfomationService.createMaterialInfomation(
                BeanUtils.toBean(createReqDTO, MaterialInfomationSaveReqVO.class));
        return success(BeanUtils.toBean(respVO, MaterialInfomationRespDTO.class));
    }*/

    @Override
    public CommonResult<Boolean> updateMaterialInfomation(MaterialInfomationSaveReqDTO updateReqDTO) {
        materialInfomationService.updateMaterialInfomation(BeanUtils.toBean(updateReqDTO, MaterialInfomationSaveReqVO.class));
        return success(true);
    }

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

    @Override
    public CommonResult<Boolean> deleteMaterialInfomationList(List<Long> ids) {
        materialInfomationService.deleteMaterialInfomationListByIds(ids);
        return success(true);
    }

    @Override
    public CommonResult<MaterialInfomationRespDTO> getMaterialInfomation(Long id) {
        MaterialInfomationRespVO respVO = materialInfomationService.getMaterialInfomation(id);
        return success(BeanUtils.toBean(respVO, MaterialInfomationRespDTO.class));
    }

    @Override
    public CommonResult<List<MaterialInfomationRespDTO>> getMaterialInfomationListByIds(List<Long> ids) {
        List<MaterialInfomationRespVO> list = materialInfomationService.getMaterialInfomationListByIds(ids);
        List<MaterialInfomationRespDTO> respList = list.stream()
                .map(item -> BeanUtils.toBean(item, MaterialInfomationRespDTO.class))
                .toList();
        return success(respList);
    }

    @Override
    public CommonResult<PageResult<MaterialInfomationRespDTO>> getMaterialInfomationPage(MaterialInfomationPageReqDTO pageReqDTO) {
        MaterialInfomationPageReqVO pageReqVO = BeanUtils.toBean(pageReqDTO, MaterialInfomationPageReqVO.class);
        PageResult<MaterialInfomationRespVO> pageResult = materialInfomationService.getMaterialInfomationPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MaterialInfomationRespDTO.class));
    }

    @Override
    public CommonResult<PageResult<MaterialInfomationSimpleRespDTO>> getMaterialInfomationSimplePage(MaterialInfomationSimplePageReqDTO pageReqDTO) {
        MaterialInfomationSimplePageReqVO pageReqVO = BeanUtils.toBean(pageReqDTO, MaterialInfomationSimplePageReqVO.class);
        PageResult<MaterialInfomationSimpleRespVO> pageResult = materialInfomationService.getMaterialInfomationSimplePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MaterialInfomationSimpleRespDTO.class));
    }
}