package gps;

import java.util.List;

import anywheresoftware.b4a.BA;
@BA.ShortName("AdzanCalculator")
public class AdzanCalculator {

	private PrayTime pt;
	
	/**
	 * Initialize the Adzan Calculator <br/>
     * By default : <br/>
     * the calculation method is Jafari <br/>
     * the Asar Juristic is Shafii <br/>
     * the Higher Latitude Adjustment is Angle Based <br/>
	 */
	public void Initialize() {
		pt = new PrayTime();
		
		pt.setTimeFormat(pt.getTime24());
	    pt.setCalcMethod(pt.getJafari());			// Jafari calculation method);		
	    pt.setAsrJuristic(pt.getShafii());			// Ashar Juristic --> Safii , dah betul
	    pt.setAdjustHighLats(pt.getAngleBased());	// Higher Latitude Adjustment --> Angle Based
	    int[] offsets = {0, 0, 0, 0, 0, 0, 0}; // {Fajr,Sunrise,Dhuhr,Asr,Sunset,Maghrib,Isha}
	    pt.tune(offsets);
	}
	
	/**
	 * Set the calculation<br/>
	 * 0 = Jafari<br/>
	 * 1 = Karachi<br/>
	 * 2 = ISNA<br/>
	 * 3 = MWL<br/>
	 * 4 = Makkah<br/>
	 * 5 = Egypt<br/>
	 * 6 = Tehran<br/>
	 * 7 = Custom<br/>
	 * default = Jafari
	 * @param method 0 -7
	 */
	public void setCalculationMethod(int method) {
		switch(method) {
		case 0:
			pt.setCalcMethod(pt.getJafari());
			break;
		case 1:
			pt.setCalcMethod(pt.getKarachi());
			break;
		case 2:
			pt.setCalcMethod(pt.getISNA());
			break;
		case 3:
			pt.setCalcMethod(pt.getMWL());
			break;
		case 4:
			pt.setCalcMethod(pt.getMakkah());
			break;
		case 5:
			pt.setCalcMethod(pt.getEgypt());
			break;
		case 6:
			pt.setCalcMethod(pt.getTehran());
			break;
		case 7:
			pt.setCalcMethod(pt.getCustom());
			break;	
		default:
			pt.setCalcMethod(pt.getJafari());
			break;
		}
	}
	
	/**
	 * Set the Asar Juristic<br/>
	 * 0 = Shafii<br/>
	 * 1 = Hanafi<br/>
	 * default = Shafii
	 * @param juristic 0 - 1
	 */
	public void setAsharJuristic(int juristic) {
		switch (juristic) {
		case 0:
			pt.setAsrJuristic(pt.getShafii());
			break;
		case 1:
			pt.setAsrJuristic(pt.getHanafi());
			break;
		default:
			pt.setAsrJuristic(pt.getShafii());
			break;
		}
	}
	
	/**
	 * Set the Higher Latitude Adjustment<br/>
	 * 0 = None : no adjustment<br/>
	 * 1 = MidNight : middle of the night<br/>
	 * 2 = OneSeventh : 1/7 of the night<br/>
	 * 3 = AngleBased : 1/60 of the night<br/>
	 * default = AngleBased
	 * @param mode
	 */
	public void setHigherLatitudeAdjustment(int mode) {
		switch (mode) {
		case 0:
			pt.setAdjustHighLats(pt.getNone());
			break;
		case 1:
			pt.setAdjustHighLats(pt.getMidNight());
			break;
		case 2:
			pt.setAdjustHighLats(pt.getOneSeventh());
			break;
		case 3:
			pt.setAdjustHighLats(pt.getAngleBased());
			break;
		default:
			pt.setAdjustHighLats(pt.getAngleBased());
			break;
		}
	}
	
	public List<String> GetPrayerNames(){
		return pt.getTimeNames();
	}
	
	public List<String> GetPrayerTime(int year, int month, int day, double latitude, double longitude, double TimeZone){
		return pt.getDatePrayerTimes(year, month, day, latitude, longitude, TimeZone);
	}
}
