package kr.co.kihyun.beans.entity;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.Discriminator;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;

import kr.co.kihyun.beans.entity.util.QueryImpl;
import kr.co.kihyun.moumi.MoumiConfig;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(strategy = InheritanceStrategy.SUPERCLASS_TABLE)
public class UnlimitStrategy extends AcceptanceLimitStrategy {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5531410697614923017L;

	private static final String filter =
		"isDeleted == false && type == TYPE_REPORT && " +
		"(process == PROCESS_COMP || process == PROCESS_END || process == PROCESS_NOT) && " +
		"totDoc == tot_doc";

	public UnlimitStrategy() {
	}

	public UnlimitStrategy(Long limitCount) {
		super(limitCount);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TotReport> getCompReports(PersistenceManager pm, Map<String, Object> filterMap) {

		QueryImpl q = new QueryImpl(pm, TotReport.class);
		q.setFilter(filter);
		q.setSearchFilter(filterMap);
		q.declareParameters("kr.co.kihyun.beans.entity.TotDoc tot_doc");
		q.setOrdering("mDept");
		return (List<TotReport>) q.execute(this.getTotDoc());
	}

	@Override
	public TotDocProcess getProcess(PersistenceManager pm) {
//		return this.getProcess();
            if(this.getTotDoc().getEndDate() != null && this.getTotDoc().getEndDate().before(new Date()))   //종료버튼 눌렀을때 조건으로 종료자료로 넘김
		return TotDocProcess.END;
            else
                return this.getProcess();
	}

	@Override
	public String getDescription(PersistenceManager pm) {
		return MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.endManually");   //수동종료
	}

}
