package de.flapdoodle.mongomapper.composite;

import org.joda.time.DateTime;

import de.flapdoodle.mongomapper.AbstractAttributeMapper;
import de.flapdoodle.mongomapper.AttributeMapper;
import de.flapdoodle.mongomapper.AttributeValueMap;
import de.flapdoodle.mongomapper.query.Properties;
import de.flapdoodle.mongomapper.query.Property;
import de.flapdoodle.mongomapper.query.QueryableCascadedProperty;
import de.flapdoodle.mongomapper.query.QueryableProperty;
import de.flapdoodle.mongomapper.types.DateMapper;
import de.flapdoodle.mongomapper.types.IntMapper;

public class QueryableDateMapper extends AbstractAttributeMapper<DateTime> {

    private static final DateMapper VALUE=new DateMapper("value");
    private static final IntMapper YEAR=new IntMapper("year");
    
    public QueryableDateMapper() {
        super(VALUE,YEAR);
    }

    @Override
    protected AttributeValueMap asAttributeMap(DateTime value) {
        return new AttributeValueMap.Builder()
            .put(VALUE, value)
            .put(YEAR, value.year().get())
            .build();
    }

    @Override
    protected DateTime asObject(AttributeValueMap attributes) {
        return attributes.get(VALUE);
    }

    public <P extends Property<?, ? extends Property<?,?>>> Value<P> value(P parent) {
        return new Value<P>(parent, this, VALUE);
    }
    
    public class Value<P extends Property<?, ? extends Property<?,?>>> extends QueryableCascadedProperty<DateTime, P> {

        public Value(P parent, QueryableDateMapper baseMapper, AttributeMapper<DateTime> valueMapper) {
            super(parent, valueMapper);
            
        }
        
        public QueryableProperty<Integer, P> year() {
            return Properties.queryable(this.parentProperty().get(), YEAR);
        }
    }
}

@@ -761,24 +761,150 @@
 er(%22year%22);%0A
+    private static final IntMapper DAY=new IntMapper(%22day%22);%0A    private static final IntMapper MONTH=new IntMapper(%22month%22);%0A
     %0A    pub
@@ -951,24 +951,34 @@
 r(VALUE,YEAR
+,DAY,MONTH
 );%0A    %7D%0A%0A  
@@ -1175,16 +1175,114 @@
 .get())%0A
+            .put(MONTH, value.monthOfYear().get())%0A            .put(DAY, value.dayOfYear().get())%0A
         
@@ -2006,20 +2006,300 @@
 ;%0A        %7D%0A
+        public QueryableProperty%3CInteger, P%3E month() %7B%0A            return Properties.queryable(this.parentProperty().get(), MONTH);%0A        %7D%0A        public QueryableProperty%3CInteger, P%3E day() %7B%0A            return Properties.queryable(this.parentProperty().get(), DAY);%0A        %7D%0A
     %7D%0A%7D%0A

date query