package org.sky.resource.rule.builder;

import org.sky.core.literule.annotation.RuleEngineComponent;
import org.sky.core.literule.builder.LiteRule;
import org.sky.core.literule.builder.RuleBuilder;
import org.sky.core.literule.builder.chain.RuleChain;
import org.sky.resource.rule.constant.OssRuleConstant;

/**
 * Oss规则链构建器
 *
 */
@RuleEngineComponent(id = OssRuleConstant.OSS_CHAIN_ID)
public class OssRuleBuilder implements RuleBuilder {
	@Override
	public RuleChain build() {
		// 创建OSS缓存判断规则链
		RuleChain ossCacheRuleChain = LiteRule.SWITCH(OssRuleConstant.OSS_CACHE_RULE).TO(
			OssRuleConstant.OSS_READ_RULE,
			LiteRule.THEN(OssRuleConstant.OSS_DATA_RULE)
				.THEN(
					LiteRule.SWITCH(OssRuleConstant.OSS_BUILD_RULE).TO(
						OssRuleConstant.ALI_OSS_RULE,
						OssRuleConstant.AMAZON_S3_RULE,
						OssRuleConstant.HUAWEI_OBS_RULE,
						OssRuleConstant.MINIO_RULE,
						OssRuleConstant.QINIU_OSS_RULE,
						OssRuleConstant.TENCENT_COS_RULE,
						OssRuleConstant.LOCAL_FILE_RULE
					).build()
				)
				.THEN(OssRuleConstant.OSS_TEMPLATE_RULE)
				.ID(OssRuleConstant.OSS_NEW_RULE)// 设置规则链ID方可在Switch节点进行调用
				.build()
		).build();

		// 创建完整规则链
		return LiteRule.THEN(OssRuleConstant.PRE_OSS_RULE)
			.THEN(ossCacheRuleChain)
			.THEN(OssRuleConstant.FINALLY_OSS_RULE)
			.build();
	}
}
