/**
 * 
 */
package org.springblade.etl.connector.source.config;

import java.util.List;
import java.util.Map;

import org.springblade.etl.connector.base.SeatunnelConfig;
import org.springblade.etl.connector.source.enums.PageConditionType;
import org.springblade.etl.connector.source.enums.PageEndFunction;
import org.springblade.etl.connector.source.enums.PageRelationType;
import org.springblade.etl.connector.source.enums.PageType;

import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author wookvn
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class SeatunnelHttpSourceConfig extends SeatunnelConfig {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String url;
	
	private SchemaField schema;
	
	@JsonProperty("json_field")
	private Map<String, String> jsonField;
	
	@JsonProperty("content_json")
	private String contentJson;
	
	/**
	 * json, text
	 */
	private String format = "json";
	
	/**
	 * GET, POST
	 */
	private String method;
	
	private Map<String, String> headers;
	
	private Map<String, String> params;
	
	private String body;
	
	@JsonProperty("poll_interval_ms")
	private Integer pollIntervalMs;
	
	private Integer retry;
	
	@JsonProperty("deep_parse_fields")
	private List<String> deepParseFields;
	
	@JsonProperty("page_param")
	private PageParam pageParam;
	
	@Data
	public static class PageParam {
		/**
		 * 是否开启分页
		 */
		@ApiModelProperty("分页开启")
		private Boolean pageEnabled = false;
		/**
		 * 分页类型：页码，偏移量，游标
		 */
		@ApiModelProperty("分页类型")
		private PageType pageType = PageType.PAGE_NUM;
		/**
		 * 分页参数名
		 */
		@ApiModelProperty("分页参数名")
		private String paramName;
		/**
		 * 限制分页取数的次数
		 */
		@ApiModelProperty("限制分页取数的次数，默认：100")
		private Integer requestMaxTimes = 100;
		/**
		 * 初始值
		 */
		@ApiModelProperty("初始值")
		private String currVal;
		/**
		 * 增长间隔
		 */
		@ApiModelProperty("增长间隔，默认：1")
		private Integer stepVal = 1;
		/**
		 * 游标方式：更新值jsonpath
		 */
		@ApiModelProperty("游标方式：更新值jsonpath")
		private String updateFieldPath;
		/**
		 * 分页结束条件关联方式
		 */
		@ApiModelProperty("分页结束条件关联方式")
		private PageRelationType endConditionRelationType = PageRelationType.AND;
		/**
		 * 分页结束条件
		 */
		@ApiModelProperty("分页结束条件")
		private List<PageCondition> endConditions;
	}
	
	@Data
	public static class PageCondition{
		@ApiModelProperty("条件类型，默认：JSON_PATH")
		private PageConditionType conditionType = PageConditionType.JSON_PATH;
		@ApiModelProperty("当条件类型=jsonpath时，需要填写")
		private String fieldPath;
		@ApiModelProperty("比较函数")
		private PageEndFunction function;
		@ApiModelProperty("数据")
		private Object value;
	}
}
