package syslog;

import anywheresoftware.b4a.BA;

@BA.ShortName("IMSI_Data")
public class IMSI_Data {
	private final String _imsi;		// always 15 digit
	private final String _mcc; // country code
	private final String _mnc; // network code
	private final String _msin;	// subscriber code
	public IMSI_Data() {
		_imsi="";
		_mcc="";
		_mnc="";
		_msin="";
	}
	
	public IMSI_Data(String value) {
		_imsi = value;
		if (_imsi.length()>=15) {
			_mcc = _imsi.substring(0, 3);		// 0,1,2 --> 3 digits
			_mnc = _imsi.substring(3,5);		// 3,4 --> 2 digits
			_msin = _imsi.substring(5);			// 5++	--> 10 digit
			
		} else {
			_mcc = "";
			_mnc = "";
			_msin = "";
		}
		
	}
	
	/**
	 * Check if IMSI_Data contains valid info
	 * @return true if valid
	 */
	public boolean isValid() {
		if (_mcc.isEmpty()) return false;
		if (_mnc.isEmpty()) return false;
		if (_msin.isEmpty()) return false;
		return true;
	}
	
	/**
	 * Check if Indonesian Network, that is MCC = 510
	 * @return true if indonesian
	 */
	public boolean isIndonesian() {
		if (_mcc.equals("510")) return true; else return false;
	}
	
	/**
	 * Get Indonesian Provider Name
	 * @return Unknown if data invalid
	 */
	public String ProviderName() {
		switch(_mnc) {
		case "10" : return "Telkomsel";
		case "11" : return "XL";
		case "01" : return "Indosat";
		case "89" : return "Three";
		case "09" : return "Smartfren";
		case "88" : return "Bolt";
		default: return "Unknown";
		}
	}
	
	/**
	 * Check if this IMSI is equal with Value
	 * @param value : other IMSi value
	 * @return true if equal
	 */
	public boolean IsEqual(String value) {
		return _imsi.equals(value);
	}
	
	/**
	 * MCC is Mobile Country Code
	 * @return empty string if invalid
	 */
	public String getMCC() {
		return _mcc;
	}
	
	/**
	 * MNC is Mobile Network Code
	 * @return empty string if invalid
	 */
	public String getMNC() {
		return _mnc;
	}
	
	/**
	 * MSIN is Mobile Subsriber Identification Number
	 * @return empty string if invalid
	 */
	public String getMSIN() {
		return _msin;
	}
}
