class ToolMapper implements EntityMapper<ToolWithDescription> {

    @Override
    public XContentBuilder map(final EntityContainer<ToolWithDescription> doc) {
        try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
            final Tool tool = doc.getEntity().getTool();
            final ToolDescription toolDescription = doc.getEntity().getToolDescription();
            jsonBuilder
                    .startObject()
                    .field(DOC_TYPE_FIELD, SearchDocumentType.TOOL.name())
                    .field("id", tool.getId())
                    .field("registry", tool.getRegistry())
                    .field("registryId", tool.getRegistryId())
                    .field("image", tool.getImage())
                    .field("createdDate", parseDataToString(tool.getCreatedDate()))
                    .field("description", tool.getDescription())
                    .field("shortDescription", tool.getShortDescription())
                    .field("defaultCommand", tool.getDefaultCommand())
                    .field("toolGroupId", tool.getToolGroupId());

            buildLabels(tool.getLabels(), jsonBuilder);
            buildVersions(toolDescription, jsonBuilder);
            buildPackages(toolDescription, jsonBuilder);

            buildUserContent(doc.getOwner(), jsonBuilder);
            buildMetadata(doc.getMetadata(), jsonBuilder);
            buildPermissions(doc.getPermissions(), jsonBuilder);

            jsonBuilder.endObject();
            return jsonBuilder;
        } catch (IOException e) {
            throw new IllegalArgumentException("Failed to create elasticsearch document for tool: ", e);
        }
    }

}