package com.thesis.centralserver.entities.mappers;

import com.thesis.centralserver.dtos.DeviceDTO;
import com.thesis.centralserver.entities.Device;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class DeviceMapper {

    public static Device createDevice(DeviceDTO deviceDTO) {

        Device device = new Device();

        device.setId(deviceDTO.getId());
        device.setIp(deviceDTO.getIp());
        device.setTotalMemory(deviceDTO.getTotalMemory());
        device.setRemainingMemory(deviceDTO.getRemainingMemory());
        device.setProcessorSpeed(deviceDTO.getProcessorSpeed());
        device.setProcessorFree(deviceDTO.getProcessorFree());
        device.setCurrencyUnitsAvailable(deviceDTO.getCurrencyUnitsAvailable());
        device.setNetworkBandWidthAvailable(deviceDTO.getNetworkBandWidthAvailable());
        device.setRemainingBattery(deviceDTO.getRemainingBattery());
        device.setDeviceMode(deviceDTO.getDeviceMode());
        device.setAlpha(deviceDTO.getAlpha());
        device.setBeta(deviceDTO.getBeta());
        device.setGamma(deviceDTO.getGamma());

        return device;

    }

    public static DeviceDTO createDeviceDTO(Device device) {

        DeviceDTO deviceDTO = new DeviceDTO();

        deviceDTO.setId(device.getId());
        deviceDTO.setIp(device.getIp());
        deviceDTO.setTotalMemory(device.getTotalMemory());
        deviceDTO.setRemainingMemory(device.getRemainingMemory());
        deviceDTO.setProcessorSpeed(device.getProcessorSpeed());
        deviceDTO.setProcessorFree(device.getProcessorFree());
        deviceDTO.setCurrencyUnitsAvailable(device.getCurrencyUnitsAvailable());
        deviceDTO.setNetworkBandWidthAvailable(device.getNetworkBandWidthAvailable());
        deviceDTO.setRemainingBattery(device.getRemainingBattery());
        deviceDTO.setDeviceMode(device.getDeviceMode());
        deviceDTO.setAlpha(device.getAlpha());
        deviceDTO.setBeta(device.getBeta());
        deviceDTO.setGamma(device.getGamma());

        return deviceDTO;

    }

    public static List<DeviceDTO> createDeviceDTOList(Collection<Device> devices) {

        return devices.stream()
                .map(DeviceMapper::createDeviceDTO)
                .collect(Collectors.toList());

    }

}
