class PipelineCodeMapper {

    public XContentBuilder pipelineCodeToDocument(final Pipeline pipeline,
                                                  final String pipelineVersion,
                                                  final String path,
                                                  final byte[] fileContent,
                                                  final PermissionsContainer permissions) {
        try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
            jsonBuilder
                    .startObject()
                    .field(DOC_TYPE_FIELD, SearchDocumentType.PIPELINE_CODE.name())
                    .field("pipelineId", pipeline.getId())
                    .field("pipelineName", pipeline.getName())
                    .field("pipelineVersion", pipelineVersion)
                    .field("path", path)
                    .field("content", buildDocContent(fileContent));

            jsonBuilder.array("allowed_users", permissions.getAllowedUsers().toArray());
            jsonBuilder.array("denied_users", permissions.getDeniedUsers().toArray());
            jsonBuilder.array("allowed_groups", permissions.getAllowedGroups().toArray());
            jsonBuilder.array("denied_groups", permissions.getDeniedGroups().toArray());

            jsonBuilder.endObject();
            return jsonBuilder;
        } catch (IOException e) {
            throw new IllegalArgumentException("An error occurred while creating document: ", e);
        }
    }

}