package org.jerrymouse.chineseCalendar.model.birthday;

import java.util.Calendar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Birthday implements Comparable<Birthday> {
	SimpleCalendar date;
	Log logger = LogFactory.getLog(Birthday.class);
	Lunar lunar;

	String name;

	public Birthday(String code) {
		super();
		int index = code.indexOf('-');
		name = code.substring(0, index);
		logger.trace(name);
		String dateStr = code.substring(++index);
		logger.trace(dateStr);
		date = new SimpleCalendar(dateStr);
	}

	public Birthday(String name, SimpleCalendar date) {
		super();
		this.name = name;
		this.date = date;
	}

	@Override
	public int compareTo(Birthday o) {
		return date.compareTo(o.getDate());
	}

	public SimpleCalendar getDate() {
		return date;
	}

	private Lunar getLunar() {
		if (lunar == null) {
			Calendar calendar = Calendar.getInstance();
			calendar.set(date.year, date.month - 1, date.day);
			lunar = new Lunar(calendar);
		}
		return lunar;

	}

	public String getLunarStr() {
		return getLunar().toDayStr();

	}

	public String getName() {
		return name;
	}

	@Override
	public String toString() {
		return name + "-" + date.year + "-" + date.month + "-" + date.day;
	}
}
