/***
 * Excerpted from "Domain-Driven Design Using Naked Objects",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/dhnako for more book information.
***/
package com.pragprog.dhnako.carserv.demo.domainservices;

import java.util.Calendar;

import org.nakedobjects.applib.AbstractService;
import org.nakedobjects.applib.annotation.MemberOrder;
import org.nakedobjects.applib.annotation.Named;
import org.nakedobjects.applib.clock.Clock;
import org.nakedobjects.applib.fixtures.FixtureClock;

import com.domainlanguage.time.CalendarDate;
import com.pragprog.dhnako.carserv.dom.domainservices.CalendarService;

public class CalendarServiceDemo 
		extends AbstractService 
		implements CalendarService {
	
	static {
		FixtureClock.initialize();
	}
	
	@MemberOrder(sequence="1")
    public CalendarDate today() {
        Calendar cal = Clock.getTimeAsCalendar();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day =  cal.get(Calendar.DATE);
        return CalendarDate.date(year, month, day);
    }
    
    // {{ turnTo
	@MemberOrder(sequence="2")
    public void turnTo(
            @Named("Year") int year, 
            @Named("Month") int month, 
            @Named("Day") int day ) {
        getFixtureClock().setDate(year, month, day);
    }
    public int default0TurnTo() {
        return Clock.getTimeAsCalendar().get(Calendar.YEAR); 
    }
    public int default1TurnTo() {
        return Clock.getTimeAsCalendar().get(Calendar.MONTH)+1; 
    }
    public int default2TurnTo() {
        return Clock.getTimeAsCalendar().get(Calendar.DATE);
    }
    // }}


    // {{ helpers
    private FixtureClock getFixtureClock() {
        return (FixtureClock) Clock.getInstance();
    }
    // }}

}
