package org.atlasapi.output.annotation;

import org.atlasapi.content.Content;
import org.atlasapi.content.Item;
import org.atlasapi.content.Series;
import org.atlasapi.output.FieldWriter;
import org.atlasapi.output.OutputContext;
import org.atlasapi.output.writers.ContainerSummaryWriter;

import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;

public class ContainerSummaryAnnotation extends OutputAnnotation<Content> {

    private final String containerField;
    private final ContainerSummaryWriter summaryWriter;
    private final ResourceRefWriter brandRefWriter;

    public ContainerSummaryAnnotation(
            String containerField,
            ContainerSummaryWriter summaryWriter,
            ResourceRefWriter brandRefWriter
    ) {
        this.containerField = checkNotNull(containerField);
        this.summaryWriter = checkNotNull(summaryWriter);
        this.brandRefWriter = checkNotNull(brandRefWriter);
    }

    @Override
    public void write(Content entity, FieldWriter writer, OutputContext ctxt) throws IOException {
        if (entity instanceof Item) {
            Item item = (Item) entity;
            if (item.getContainerRef() == null) {
                writer.writeField(containerField, null);
            } else {
                writer.writeObject(summaryWriter, item, ctxt);
            }
        }
        //code disabled because because the made the ChangesContent	queue skyrocket. Maybe some
        //sort of loop?
//        else if (entity instanceof Series) {
//            Series series = (Series) entity;
//            if (series.getBrandRef() == null) {
//                writer.writeField(containerField, null);
//            } else {
//                writer.writeObject(brandRefWriter, series.getBrandRef(), ctxt);
//            }
//        }
    }

}

@@ -1375,138 +1375,8 @@
    %7D
-%0A        //code disabled because because the made the ChangesContent%09queue skyrocket. Maybe some%0A        //sort of loop?%0A//       
  els
@@ -1405,26 +1405,24 @@
 f Series) %7B%0A
-//
             
@@ -1454,18 +1454,16 @@
 entity;%0A
-//
         
@@ -1502,18 +1502,16 @@
 null) %7B%0A
-//
         
@@ -1559,18 +1559,16 @@
  null);%0A
-//
         
@@ -1580,18 +1580,16 @@
  else %7B%0A
-//
         
@@ -1660,18 +1660,16 @@
  ctxt);%0A
-//
         
@@ -1678,10 +1678,8 @@
   %7D%0A
-//
     

Revert "hotfix: disable brand ref writter for series"