class InstanceMetaDataToCloudInstanceConverter extends AbstractConversionServiceAwareConverter<InstanceMetaData, CloudInstance> {

    @Override
    public CloudInstance convert(InstanceMetaData metaDataEntity) {
        InstanceGroup group = metaDataEntity.getInstanceGroup();
        Template template = group.getTemplate();
        Stack stack = group.getStack();
        StackAuthentication stackAuthentication = stack.getStackAuthentication();
        InstanceStatus status = getInstanceStatus(metaDataEntity);
        String imageId = instanceMetadataToImageIdConverter.convert(metaDataEntity);
        InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEntity.getPrivateId(),
                status, imageId);
        InstanceAuthentication instanceAuthentication = new InstanceAuthentication(
                stackAuthentication.getPublicKey(),
                stackAuthentication.getPublicKeyId(),
                stackAuthentication.getLoginUserName());
        Map<String, Object> params = new HashMap<>();
        params.put(CloudInstance.SUBNET_ID, metaDataEntity.getSubnetId());
        params.put(CloudInstance.INSTANCE_NAME, metaDataEntity.getInstanceName());

        Map<String, Object> cloudInstanceParameters = stackToCloudStackConverter.buildCloudInstanceParameters(
                stack.getEnvironmentCrn(),
                metaDataEntity,
                CloudPlatform.valueOf(stack.getCloudPlatform()));
        params.putAll(cloudInstanceParameters);

        return new CloudInstance(metaDataEntity.getInstanceId(), instanceTemplate, instanceAuthentication, params);
    }

}