/*
 * Copyright 2013-present the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.cloud.stream.binder.rocketmq.properties;

import org.jspecify.annotations.Nullable;

/**
 * Extended producer properties for RocketMQ binder.
 *
 * @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
 */
public class RocketMQProducerProperties extends RocketMQCommonProperties {

	/**
	 * Timeout for sending messages.
	 */
	private int sendMsgTimeout = 3000;

	/**
	 * Compress message body threshold, namely, message body larger than 4k will be
	 * compressed on default.
	 */
	private int compressMsgBodyThreshold = 1024 * 4;

	/**
	 * Maximum number of retry to perform internally before claiming sending failure in
	 * synchronous mode.
	 *
	 * This may potentially cause message duplication which is up to application
	 * developers to resolve.
	 */
	private int retryTimesWhenSendFailed = 2;

	/**
	 * Maximum number of retry to perform internally before claiming sending failure in
	 * asynchronous mode.
	 *
	 * This may potentially cause message duplication which is up to application
	 * developers to resolve.
	 */
	private int retryTimesWhenSendAsyncFailed = 2;

	/**
	 * Indicate whether to retry another broker on sending failure internally.
	 */
	private boolean retryAnotherBroker = false;

	/**
	 * Maximum allowed message size in bytes.
	 */
	private int maxMessageSize = 1024 * 1024 * 4;

	private String producerType = ProducerType.Normal.name();

	private String sendType = SendType.Sync.name();

	private @Nullable String sendCallBack;

	private @Nullable String transactionListener;

	private @Nullable String messageQueueSelector;

	private @Nullable String errorMessageStrategy;

	private @Nullable String sendFailureChannel;

	private @Nullable String checkForbiddenHook;

	private @Nullable String sendMessageHook;

	public int getSendMsgTimeout() {
		return sendMsgTimeout;
	}

	public void setSendMsgTimeout(int sendMsgTimeout) {
		this.sendMsgTimeout = sendMsgTimeout;
	}

	public int getCompressMsgBodyThreshold() {
		return compressMsgBodyThreshold;
	}

	public void setCompressMsgBodyThreshold(int compressMsgBodyThreshold) {
		this.compressMsgBodyThreshold = compressMsgBodyThreshold;
	}

	public int getRetryTimesWhenSendFailed() {
		return retryTimesWhenSendFailed;
	}

	public void setRetryTimesWhenSendFailed(int retryTimesWhenSendFailed) {
		this.retryTimesWhenSendFailed = retryTimesWhenSendFailed;
	}

	public int getRetryTimesWhenSendAsyncFailed() {
		return retryTimesWhenSendAsyncFailed;
	}

	public void setRetryTimesWhenSendAsyncFailed(int retryTimesWhenSendAsyncFailed) {
		this.retryTimesWhenSendAsyncFailed = retryTimesWhenSendAsyncFailed;
	}

	public boolean getRetryAnotherBroker() {
		return retryAnotherBroker;
	}

	public void setRetryAnotherBroker(boolean retryAnotherBroker) {
		this.retryAnotherBroker = retryAnotherBroker;
	}

	public int getMaxMessageSize() {
		return maxMessageSize;
	}

	public void setMaxMessageSize(int maxMessageSize) {
		this.maxMessageSize = maxMessageSize;
	}

	public String getProducerType() {
		return producerType;
	}

	public void setProducerType(String producerType) {
		this.producerType = producerType;
	}

	public String getSendType() {
		return sendType;
	}

	public void setSendType(String sendType) {
		this.sendType = sendType;
	}

	public @Nullable String getSendCallBack() {
		return sendCallBack;
	}

	public void setSendCallBack(@Nullable String sendCallBack) {
		this.sendCallBack = sendCallBack;
	}

	public @Nullable String getTransactionListener() {
		return transactionListener;
	}

	public void setTransactionListener(@Nullable String transactionListener) {
		this.transactionListener = transactionListener;
	}

	public @Nullable String getMessageQueueSelector() {
		return messageQueueSelector;
	}

	public void setMessageQueueSelector(@Nullable String messageQueueSelector) {
		this.messageQueueSelector = messageQueueSelector;
	}

	public @Nullable String getErrorMessageStrategy() {
		return errorMessageStrategy;
	}

	public void setErrorMessageStrategy(@Nullable String errorMessageStrategy) {
		this.errorMessageStrategy = errorMessageStrategy;
	}

	public @Nullable String getSendFailureChannel() {
		return sendFailureChannel;
	}

	public void setSendFailureChannel(@Nullable String sendFailureChannel) {
		this.sendFailureChannel = sendFailureChannel;
	}

	public @Nullable String getCheckForbiddenHook() {
		return checkForbiddenHook;
	}

	public void setCheckForbiddenHook(@Nullable String checkForbiddenHook) {
		this.checkForbiddenHook = checkForbiddenHook;
	}

	public @Nullable String getSendMessageHook() {
		return sendMessageHook;
	}

	public void setSendMessageHook(@Nullable String sendMessageHook) {
		this.sendMessageHook = sendMessageHook;
	}

	public enum ProducerType {

		/**
		 * Is not a transaction.
		 */
		Normal,
		/**
		 * a transaction.
		 */
		Trans;

		public boolean equalsName(String name) {
			return this.name().equalsIgnoreCase(name);
		}

	}

	public enum SendType {

		/**
		 * one way.
		 */
		OneWay,
		/**
		 * Asynchronization Model.
		 */
		Async,
		/**
		 * synchronization.
		 */
		Sync,;

		public boolean equalsName(String name) {
			return this.name().equalsIgnoreCase(name);
		}

	}

}
