package cn.iocoder.yudao.module.configure.api.deviceenvtype;

import cn.hutool.core.bean.BeanUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.configure.api.deviceenvtype.dto.DeviceEnvTypeCreateReqDTO;
import cn.iocoder.yudao.module.configure.api.deviceenvtype.dto.DeviceEnvTypeRespDTO;
import cn.iocoder.yudao.module.configure.api.deviceenvtype.dto.DeviceEnvTypeUpdateReqDTO;
import cn.iocoder.yudao.module.configure.controller.admin.deviceenvtype.vo.DeviceEnvTypeCreateReqVO;
import cn.iocoder.yudao.module.configure.controller.admin.deviceenvtype.vo.DeviceEnvTypeUpdateReqVO;
import cn.iocoder.yudao.module.configure.enums.ApiConstants;
import cn.iocoder.yudao.module.configure.service.deviceenvtype.DeviceEnvTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = ApiConstants.VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
@Slf4j
public class DeviceEnvTypeApiImpl implements DeviceEnvTypeApi {

    @Resource
    private DeviceEnvTypeService deviceEnvTypeService;

    @Override
    @Transactional
    public CommonResult<List<Long>> createDeviceEnvTypeBatch(List<DeviceEnvTypeCreateReqDTO> createReqDTOS) {
        List<DeviceEnvTypeCreateReqVO> createReq = BeanUtil.copyToList(createReqDTOS, DeviceEnvTypeCreateReqVO.class);
        return CommonResult.success(deviceEnvTypeService.createDeviceEnvTypeBatch(createReq));
    }

    @Override
    @Transactional
    public CommonResult<Boolean> updateDeviceEnvTypeBatch(List<DeviceEnvTypeUpdateReqDTO> updateReqDTOS) {
        List<DeviceEnvTypeUpdateReqVO> updateReq = BeanUtil.copyToList(updateReqDTOS, DeviceEnvTypeUpdateReqVO.class);
        deviceEnvTypeService.updateDeviceEnvTypeBatch(updateReq);
        return CommonResult.success(Boolean.TRUE);
    }

    @Override
    @Transactional
    public CommonResult<Boolean> deleteDeviceEnvTypeBatch(List<Long> ids) {
        deviceEnvTypeService.deleteDeviceEnvTypeBatch(ids);
        return CommonResult.success(Boolean.TRUE);
    }

    @Override
    public CommonResult<List<DeviceEnvTypeRespDTO>> getByLandId(String landId) {
        return CommonResult.success(BeanUtil.copyToList(deviceEnvTypeService.getByLandId(landId), DeviceEnvTypeRespDTO.class));
    }
}
