/**
 * 
 */
package org.apache.seatunnel.connectors.seatunnel.http.enums;

import java.math.BigDecimal;

/**
 * @author wookvn
 *
 */
public enum PageEndFunction {

	EQ {
		@Override
		public boolean compare(Object value, Object compareVal) {
			return value == null || value.equals(compareVal);
		}
	},
	
	NE {
		@Override
		public boolean compare(Object value, Object compareVal) {
			return value == null || !value.equals(compareVal);
		}
	},
	
	GT {
		@Override
		public boolean compare(Object value, Object compareVal) {
			if(value != null && compareVal != null){
				try {
					BigDecimal valueBigDecimal = new BigDecimal(value.toString());
					BigDecimal compareValBigDecimal = new BigDecimal(compareVal.toString());
					return valueBigDecimal.compareTo(compareValBigDecimal) > 0;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return true;
		}
	},
	
	GE {
		@Override
		public boolean compare(Object value, Object compareVal) {
			if(value != null && compareVal != null){
				try {
					BigDecimal valueBigDecimal = new BigDecimal(value.toString());
					BigDecimal compareValBigDecimal = new BigDecimal(compareVal.toString());
					return valueBigDecimal.compareTo(compareValBigDecimal) >= 0;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return true;
		}
	},
	
	LT {
		@Override
		public boolean compare(Object value, Object compareVal) {
			if(value != null && compareVal != null){
				try {
					BigDecimal valueBigDecimal = new BigDecimal(value.toString());
					BigDecimal compareValBigDecimal = new BigDecimal(compareVal.toString());
					return valueBigDecimal.compareTo(compareValBigDecimal) < 0;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return true;
		}
	},
	
	LE {
		@Override
		public boolean compare(Object value, Object compareVal) {
			if(value != null && compareVal != null){
				try {
					BigDecimal valueBigDecimal = new BigDecimal(value.toString());
					BigDecimal compareValBigDecimal = new BigDecimal(compareVal.toString());
					return valueBigDecimal.compareTo(compareValBigDecimal) <= 0;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return true;
		}
	},
	
	IS_NULL {
		@Override
		public boolean compare(Object value, Object compareVal) {
			return value == null;
		}
	},
	
	NOT_NULL {
		@Override
		public boolean compare(Object value, Object compareVal) {
			return value != null;
		}
	},
	
	IN {
		@Override
		public boolean compare(Object value, Object compareVal) {
			return value == null || compareVal == null || compareVal.toString().contains(value.toString());
		}
	},
	
	NOT_IN {
		@Override
		public boolean compare(Object value, Object compareVal) {
			return value == null || compareVal == null || !compareVal.toString().contains(value.toString());
		}
	},
	
	;

	/**
	 * 比较两个值
	 * @param value
	 * @param compareVal
	 * @return
	 */
	public abstract boolean compare(Object value, Object compareVal);
}
