package ca.antonious.viewcelladapter.construction;

import ca.antonious.viewcelladapter.decorators.ItemDividerSectionDecorator;
import ca.antonious.viewcelladapter.internal.Function;
import ca.antonious.viewcelladapter.decorators.EmptySectionDecorator;
import ca.antonious.viewcelladapter.decorators.FooterSectionDecorator;
import ca.antonious.viewcelladapter.decorators.HeaderSectionDecorator;
import ca.antonious.viewcelladapter.decorators.SectionDecorator;
import ca.antonious.viewcelladapter.sections.AbstractSection;
import ca.antonious.viewcelladapter.sections.CompositeSection;
import ca.antonious.viewcelladapter.sections.HomogeneousSection;
import ca.antonious.viewcelladapter.viewcells.AbstractViewCell;
import ca.antonious.viewcelladapter.viewcells.GenericViewCell;
import ca.antonious.viewcelladapter.viewcells.builtins.MaterialDividerViewCell;

/**
 * Created by George on 2017-04-22.
 */

public class SectionBuilder<TSection extends AbstractSection> {
    public TSection section;

    public SectionBuilder(TSection section) {
        this.section = section;
    }

    public TSection getSection() {
        return section;
    }

    public TSection build() {
        return getSection();
    }

    public static <TSection extends AbstractSection> SectionBuilder<TSection> wrap(TSection section) {
        return new SectionBuilder<>(section);
    }

    public static <TModel, TViewCell extends GenericViewCell<?, TModel>> HomogeneousSectionBuilder<TModel, TViewCell> wrap(HomogeneousSection<TModel, TViewCell> section) {
        return new HomogeneousSectionBuilder<>(section);
    }

    public static CompositeSectionBuilder createCompositeSection() {
        return new CompositeSectionBuilder(new CompositeSection());
    }

    public HeaderDecoratorBuilder header(AbstractViewCell headerViewCell) {
        HeaderSectionDecorator decorator = new HeaderSectionDecorator(getSection(), headerViewCell);
        return new HeaderDecoratorBuilder(decorator);
    }

    public FooterDecoratorBuilder footer(AbstractViewCell footerViewCell) {
        FooterSectionDecorator decorator = new FooterSectionDecorator(getSection(), footerViewCell);
        return new FooterDecoratorBuilder(decorator);
    }

    public EmptySectionBuilder showIfEmpty(AbstractViewCell emptyViewCell) {
        EmptySectionDecorator decorator = new EmptySectionDecorator(getSection(), emptyViewCell);
        return new EmptySectionBuilder(decorator);
    }

    public ItemDividerBuilder separateWithDividers() {
        return separateWithDividers(new Function<AbstractViewCell, AbstractViewCell>() {
            @Override
            public AbstractViewCell apply(AbstractViewCell viewCellBeforeDivider) {
                return new MaterialDividerViewCell(viewCellBeforeDivider.getItemId());
            }
        });
    }

    public ItemDividerBuilder separateWithDividers(Function<? super AbstractViewCell, ? extends AbstractViewCell> viewCellFactory) {
        ItemDividerSectionDecorator decorator = new ItemDividerSectionDecorator(getSection(), viewCellFactory);
        return new ItemDividerBuilder(decorator);
    }

    public <TDecorator extends SectionDecorator> SectionBuilder<TDecorator> decorateWith(Function<? super AbstractSection, ? extends TDecorator> decoratorFactory) {
        return new SectionBuilder<>(decoratorFactory.apply(getSection()));
    }

}

@@ -45,16 +45,64 @@
 ction;%0A%0A
+import android.support.v7.widget.RecyclerView;%0A%0A
 import c
@@ -161,32 +161,32 @@
 ctionDecorator;%0A
-
 import ca.antoni
@@ -555,32 +555,100 @@
 bstractSection;%0A
+import ca.antonious.viewcelladapter.sections.AdapterWrapperSection;%0A
 import ca.antoni
@@ -1470,33 +1470,37 @@
 section);%0A    %7D%0A
+    
 %0A
-
     public stati
@@ -1647,32 +1647,32 @@
 ell%3E section) %7B%0A
-
         return n
@@ -1711,32 +1711,279 @@
 ection);%0A    %7D%0A%0A
+    public static %3CTViewHolder extends RecyclerView.ViewHolder%3E SectionBuilder%3CAdapterWrapperSection%3CTViewHolder%3E%3E wrap(RecyclerView.Adapter%3CTViewHolder%3E adapter) %7B%0A        return new SectionBuilder%3C%3E(new AdapterWrapperSection%3C%3E(adapter));%0A    %7D%0A%0A
     public stati

Add AdapterWrapperSection to the SectionBuilder API