package org.estatio.dom.numerator;

import java.util.List;

import org.apache.isis.applib.AbstractFactoryAndRepository;
import org.apache.isis.applib.annotation.ActionSemantics;
import org.apache.isis.applib.annotation.ActionSemantics.Of;
import org.apache.isis.applib.annotation.Hidden;
import org.apache.isis.applib.annotation.Named;
import org.apache.isis.applib.filter.Filter;

@Named("Numerators")
public class Numerators extends AbstractFactoryAndRepository {

    // {{ Id, iconName
    @Override
    public String getId() {
        return "numerators";
    }

    public String iconName() {
        return "Numerator";
    }

    // }}

    @Hidden
    public Numerator create(NumeratorType type) {
        Numerator numerator = type.create(getContainer());
        persist(numerator);
        return numerator;
    }

    @Hidden
    public Numerator find(final NumeratorType type) {
        Numerator numerator = firstMatch(Numerator.class, new Filter<Numerator>() {
            @Override
            public boolean accept(final Numerator n) {
                return n.getType().equals(type);
            }
        });
        return numerator;
    }

    @ActionSemantics(Of.NON_IDEMPOTENT)
    public Numerator establish(NumeratorType type) {
        Numerator numerator = find(type);
        return numerator == null ? create(type) : numerator;
    }

    // {{ allNumerators
    @ActionSemantics(Of.SAFE)
    public List<Numerator> allNumerators() {
        List<Numerator> allInstances = allInstances(Numerator.class);
        return allInstances;
    }
    // }}

}

@@ -638,16 +638,210 @@
  // %7D%7D%0A%0A
+    @Hidden%0A    public NumeratorForInvoiceNumber dummyNFIN() %7B%0A        return null;%0A    %7D%0A    %0A    @Hidden %0A    public NumeratorForCollectionNumber dummyNFCN() %7B%0A        return null;%0A    %7D%0A    %0A
     @Hid

add dummy methods to full instantiate the metamodel