/**
 * @date 2020年3月23日  
 * @author 翁东州
 * @方法中文名称:
 */
package cn.timer.api.config.enuminterface;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;


import lombok.Getter;

/**
 * @date 2020年3月23日  
 * @author 翁东州
 * @方法中文名称:
 */

public interface YgEnumInterface {
	/**
	 * 男女
	 */
	@Getter
	enum sex implements YgEnumInterface{
		MAN(0,"男"),WOMAN(1,"女");
		
		private Integer type;

		private String name;
		
		sex(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
		public static String isMan(String index) {
			sex mow = (index == null || index.length() == 0) ? sex.MAN : (index.indexOf(sex.MAN.name)!= -1)||(index.indexOf(sex.MAN.type)!= -1) ? sex.MAN:sex.WOMAN;
			return mow.type.toString();			
		}
	}
	/**
	 * 员工类型
	 */
	@Getter
	enum YgJobType  implements YgEnumInterface{
		QUANZHI(1, "全"),SHIXI(2, "实习"),JIANZHI(3, "兼"),LWPQ(4, "劳务派遣"),
		LAOWU(5, "劳务"),PAIQIAN(6, "派遣"),WAIBAO(7, "外包"),TUIXIU(8, "退休");

		private Integer type;

		private String name;

		YgJobType(Integer type, String name) {
			this.type = type;
			this.name = name;
		}

		public static String choose(String index) {
			YgJobType result = YgJobType.QUANZHI;
			if(index == null || index.length() == 0) return result.type.toString();
			for (YgJobType item : YgJobType.values()) {
				if (index.indexOf(item.getType()) !=-1 ||index.indexOf(item.getName()) !=-1 ) result = item;
			}
			return result.type.toString();
		}
	}
	
	/**
	 * 员工状态
	 */
	@Getter
	enum jobStatus implements YgEnumInterface{
		ZHENSHI(0,"正式"),SHIYONG(1,"试用");
		
		private Integer type;

		private String name;
		
		jobStatus(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
		public static String isZhen(String index) {
			jobStatus zos = (index == null || index.length() == 0) ? YgEnumInterface.jobStatus.ZHENSHI: (index.indexOf(jobStatus.ZHENSHI.name)!= -1)||(index.indexOf(jobStatus.ZHENSHI.type)!= -1) ? jobStatus.ZHENSHI:jobStatus.SHIYONG;
			return zos.type.toString();
		}
	}
	
	/**
	 * 入职日期
	 */
	@Getter
	enum rzTime  implements YgEnumInterface{
		ZHEN("--","yyyy-M-d"),XIE("//","yyyy/M/d"),
		DIAN("..","yyyy.M.d"),NYR("年月日","yyyy年M月d日");
		
		private String type;

		private String name;

		rzTime(String type, String name) {
			this.type = type;
			this.name = name;
		}
		
		public static String tranTime(String index) {
			DateFormat zhenFormat = new SimpleDateFormat(ZHEN.name);
			String result = zhenFormat.format(new Date());
			if (index == null || index.length() == 0) return result;
			Pattern pattern = Pattern.compile("^[0-9]{8}$"); 
		    if (pattern.matcher(index).matches()) {
				result = index.substring(0, 4) + "-" + index.substring(4, 6) + "-" + index.substring(6, 8);
				return result;
			}
			String s = index.replaceAll("([1-9]+[0-9]*|0)(\\.[\\d]+)?", "");
			for (rzTime item : rzTime.values()) {
				if (s.indexOf(item.type) != -1) {
					  DateFormat dateFormat = new SimpleDateFormat(item.name);
					try {
						result = new SimpleDateFormat(ZHEN.name).format(dateFormat.parse(index));
						return result;
					} catch (ParseException e) {
						e.printStackTrace();
						return result;
					}
				}
			}
			return result;
		}
		
		
		public static String tranTime2(String result) {
			String isYear ="^(?:(?!0000)[0-9]{4} -(?:(?:0[1-9]|1[0-2]) -(?:0[1-9]|1[0-9]|2[0-8]) |(?:0[13-9]|1[0-2]) -(?:29|30) |(?:0[13578]|1[02]) -31 )|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00) -02 -29 )$";
			Pattern pattern = Pattern.compile(isYear);
			if (pattern.matcher(result).matches()) {
				return result;
			}else {
				 result = new SimpleDateFormat(ZHEN.name).format(new Date());
				return result;
			}
			
		}
	}
	/**
	 * 试用期
	 */
	@Getter
	enum syq implements YgEnumInterface{
		ZERO(0,"无"),ONE(1,"一"),TWO(2,"二"),THREE(3,"三"),FOUR(4,"四"),FIVE(5,"五"),SIX(6,"六");
		
		private Integer type;

		private String name;
		
		syq(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
		public static String choose(String index) {
			syq result = syq.ZERO;
			if (index == null || index.length() == 0) result.type.toString();
			for (syq item : syq.values()) {
				if (index.indexOf(item.getName()) !=-1 ||index.indexOf(item.getType()) !=-1 ) result=item;
			}
			return result.type.toString();
		}
	}
}