class DeviceConverter extends BidirectionalConverter<SmartMeteringDeviceDto, DlmsDevice> {

    @Override
    public DlmsDevice convertTo(final SmartMeteringDeviceDto source, final Type<DlmsDevice> destinationType,
            final MappingContext context) {
        final DlmsDevice dlmsDevice = new DlmsDevice();
        dlmsDevice.setDeviceIdentification(source.getDeviceIdentification());
        dlmsDevice.setCommunicationMethod(source.getCommunicationMethod());
        dlmsDevice.setCommunicationProvider(source.getCommunicationProvider());
        dlmsDevice.setIccId(source.getICCId());
        dlmsDevice.setHls3Active(source.isHLS3Active());
        dlmsDevice.setHls4Active(source.isHLS4Active());
        dlmsDevice.setHls5Active(source.isHLS5Active());
        dlmsDevice.setMbusIdentificationNumber(source.getMbusIdentificationNumber());
        dlmsDevice.setMbusManufacturerIdentification(source.getMbusManufacturerIdentification());
        dlmsDevice.setProtocol(source.getProtocolName(), source.getProtocolVersion());

        if (source.getMasterKey() != null) {
            dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.E_METER_MASTER,
                    Hex.encodeHexString(source.getMasterKey()), source.getDeliveryDate(), null));
        }

        if (source.getAuthenticationKey() != null) {
            dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.E_METER_AUTHENTICATION,
                    Hex.encodeHexString(source.getAuthenticationKey()), source.getDeliveryDate(), null));
        }

        if (source.getGlobalEncryptionUnicastKey() != null) {
            dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.E_METER_ENCRYPTION,
                    Hex.encodeHexString(source.getGlobalEncryptionUnicastKey()), source.getDeliveryDate(), null));
        }

        if (source.getMbusDefaultKey() != null) {
            dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.G_METER_MASTER,
                    Hex.encodeHexString(source.getMbusDefaultKey()), source.getDeliveryDate(), null));
        }

        return dlmsDevice;
    }

}