package com.goafanti.report.enums;

import java.util.HashMap;
import java.util.Map;

public enum SalesReportOrderField {
	DailyOrderCount("dailyOrderCount", "每日订单量"),
	DailyOrderAmount("dailyOrderAmount", "每日订单金额"),
	WeeklyOrderCount("weeklyOrderCount", "每周订单量"),
	WeeklyOrderAmount("weeklyOrderAmount", "每周订单金额"),
	MonthlyOrderCount("monthlyOrderCount", "每月订单量"),
	MonthlyOrderAmount("monthlyOrderAmount", "每月订单金额"),
	QuarterlyOrderCount("quarterlyOrderCount", "每季度订单量"),
	QuarterlyOrderAmount("quarterlyOrderAmount", "每季度订单金额"),
	AnnuallyOrderCount("annuallyOrderCount", "每年订单量"),
	AnnuallyOrderAmount("annuallyOrderAmount", "每年订单金额");

	private SalesReportOrderField(String code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	private static Map<String, SalesReportOrderField> status = new HashMap<String, SalesReportOrderField>();

	static {
		for (SalesReportOrderField value : values()) {
			status.put(value.getCode(), value);
		}
	}

	public static SalesReportOrderField getField(String code) {
		if (containsType(code)) {
			return status.get(code);
		}
		return DailyOrderAmount;
	}

	public static boolean isDaily(SalesReportOrderField field) {
		return field == DailyOrderAmount || field == DailyOrderCount;
	}

	public static boolean isWeekly(SalesReportOrderField field) {
		return field == WeeklyOrderAmount || field == WeeklyOrderCount;
	}

	public static boolean isMonthly(SalesReportOrderField field) {
		return field == MonthlyOrderAmount || field == MonthlyOrderCount;
	}

	public static boolean isQuarterly(SalesReportOrderField field) {
		return field == QuarterlyOrderAmount || field == QuarterlyOrderCount;
	}

	public static boolean isAnnually(SalesReportOrderField field) {
		return field == AnnuallyOrderAmount || field == AnnuallyOrderCount;
	}

	public static boolean containsType(String code) {
		return status.containsKey(code);
	}

	private String	code;
	private String	desc;

	public String getCode() {
		return code;
	}

	public String getDesc() {
		return desc;
	}
}
