// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.messaging.servicebus.administration.models;

import com.azure.core.annotation.Fluent;
import com.azure.messaging.servicebus.administration.ServiceBusAdministrationAsyncClient;
import com.azure.messaging.servicebus.administration.ServiceBusAdministrationClient;
import com.azure.messaging.servicebus.administration.implementation.EntityHelper;
import com.azure.messaging.servicebus.administration.implementation.models.EntityAvailabilityStatusImpl;
import com.azure.messaging.servicebus.administration.implementation.models.MessageCountDetailsImpl;
import com.azure.messaging.servicebus.administration.implementation.models.SubscriptionDescriptionImpl;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.Objects;

import static com.azure.messaging.servicebus.implementation.MessageUtils.toPrimitive;

/**
 * Properties on a subscription.
 *
 * @see ServiceBusAdministrationAsyncClient#getSubscription(String, String)
 * @see ServiceBusAdministrationClient#getSubscription(String, String)
 */
@Fluent
public final class SubscriptionProperties {
    private final SubscriptionDescriptionImpl description;

    static {
        // This is used by classes in different packages to get access to private and package-private methods.
        EntityHelper.setSubscriptionAccessor(new EntityHelper.SubscriptionAccessor() {
            @Override
            public SubscriptionProperties toModel(SubscriptionDescriptionImpl description) {
                return new SubscriptionProperties(description);
            }

            @Override
            public SubscriptionDescriptionImpl toImplementation(SubscriptionProperties subscription) {
                return subscription.description;
            }

            @Override
            public void setTopicName(SubscriptionProperties subscriptionProperties, String topicName) {
                subscriptionProperties.setTopicName(topicName);
            }

            @Override
            public void setSubscriptionName(SubscriptionProperties subscriptionProperties, String subscriptionName) {
                subscriptionProperties.setSubscriptionName(subscriptionName);
            }
        });
    }

    private String topicName;
    private String subscriptionName;

    /**
     * Creates a new instance with the given options.
     *
     * @param description Options used to create a subscription.
     */
    SubscriptionProperties(SubscriptionDescriptionImpl description) {
        Objects.requireNonNull(description, "'description' cannot be null.");
        this.description = description;
    }

    /**
     * Gets the name of the topic under which subscription exists.
     * @return The name of the topic under which subscription exists.
     */
    public String getTopicName() {
        return topicName;
    }

    /**
     * Sets the name of the topic.
     *
     * @param topicName Name of the topic.
     * @return the SubscriptionProperties object itself.
     */
    SubscriptionProperties setTopicName(String topicName) {
        this.topicName = topicName;
        return this;
    }

    /**
     * Gets the name of the subscription.
     *
     * @return The name of the subscription.
     */
    public String getSubscriptionName() {
        return subscriptionName;
    }

    /**
     * Sets the name of the subscription.
     *
     * @param subscriptionName Name of the subscription.
     * @return the SubscriptionProperties object itself.
     */
    SubscriptionProperties setSubscriptionName(String subscriptionName) {
        this.subscriptionName = subscriptionName;
        return this;
    }

    /**
     * Get the lockDuration property: ISO 8601 timespan duration of a peek-lock; that is, the amount of time that the
     * message is locked for other receivers. The maximum value for LockDuration is 5 minutes; the default value is 1
     * minute.
     *
     * @return the lockDuration value.
     */
    public Duration getLockDuration() {
        return description.getLockDuration();
    }

    /**
     * Set the lockDuration property: ISO 8601 timespan duration of a peek-lock; that is, the amount of time that the
     * message is locked for other receivers. The maximum value for LockDuration is 5 minutes; the default value is 1
     * minute.
     *
     * @param lockDuration the lockDuration value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setLockDuration(Duration lockDuration) {
        description.setLockDuration(lockDuration);
        return this;
    }

    /**
     * Get the requiresSession property: A value that indicates whether the queue supports the concept of sessions.
     *
     * @return the requiresSession value.
     */
    public boolean isSessionRequired() {
        return toPrimitive(description.isRequiresSession());
    }

    /**
     * Get the defaultMessageTimeToLive property: ISO 8601 default message timespan to live value. This is the duration
     * after which the message expires, starting from when the message is sent to Service Bus. This is the default value
     * used when TimeToLive is not set on a message itself.
     *
     * @return the defaultMessageTimeToLive value.
     */
    public Duration getDefaultMessageTimeToLive() {
        return description.getDefaultMessageTimeToLive();
    }

    /**
     * Set the defaultMessageTimeToLive property: ISO 8601 default message timespan to live value. This is the duration
     * after which the message expires, starting from when the message is sent to Service Bus. This is the default value
     * used when TimeToLive is not set on a message itself.
     *
     * @param defaultMessageTimeToLive the defaultMessageTimeToLive value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive) {
        description.setDefaultMessageTimeToLive(defaultMessageTimeToLive);
        return this;
    }

    /**
     * Get the deadLetteringOnMessageExpiration property: A value that indicates whether this subscription has dead
     * letter support when a message expires.
     *
     * @return the deadLetteringOnMessageExpiration value.
     */
    public boolean isDeadLetteringOnMessageExpiration() {
        return toPrimitive(description.isDeadLetteringOnMessageExpiration());
    }

    /**
     * Set the deadLetteringOnMessageExpiration property: A value that indicates whether this subscription has dead
     * letter support when a message expires.
     *
     * @param deadLetteringOnMessageExpiration the deadLetteringOnMessageExpiration value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setDeadLetteringOnMessageExpiration(boolean deadLetteringOnMessageExpiration) {
        description.setDeadLetteringOnMessageExpiration(deadLetteringOnMessageExpiration);
        return this;
    }

    /**
     * Get the deadLetteringOnFilterEvaluationExceptions property: A value that indicates whether this subscription has
     * dead letter support when a message expires.
     *
     * @return the deadLetteringOnFilterEvaluationExceptions value.
     */
    public boolean isDeadLetteringOnFilterEvaluationExceptions() {
        return toPrimitive(description.isDeadLetteringOnFilterEvaluationExceptions());
    }

    /**
     * Set the deadLetteringOnFilterEvaluationExceptions property: A value that indicates whether this subscription has
     * dead letter support when a message expires.
     *
     * @param deadLetteringOnFilterEvaluationExceptions the deadLetteringOnFilterEvaluationExceptions value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setEnableDeadLetteringOnFilterEvaluationExceptions(
            boolean deadLetteringOnFilterEvaluationExceptions) {
        description.setDeadLetteringOnFilterEvaluationExceptions(deadLetteringOnFilterEvaluationExceptions);
        return this;
    }

    /**
     * Get the messageCount property: The number of messages in the subscription.
     *
     * @return the messageCount value.
     */
    int getMessageCount() {
        return toPrimitive(description.getMessageCount());
    }

    /**
     * Set the messageCount property: The number of messages in the subscription.
     *
     * @param messageCount the messageCount value to set.
     * @return the SubscriptionProperties object itself.
     */
    SubscriptionProperties setMessageCount(int messageCount) {
        description.setMessageCount(messageCount);
        return this;
    }

    /**
     * Get the maxDeliveryCount property: The maximum delivery count. A message is automatically deadlettered after this
     * number of deliveries. Default value is 10.
     *
     * @return the maxDeliveryCount value.
     */
    public int getMaxDeliveryCount() {
        return toPrimitive(description.getMaxDeliveryCount());
    }

    /**
     * Set the maxDeliveryCount property: The maximum delivery count. A message is automatically deadlettered after this
     * number of deliveries. Default value is 10.
     *
     * @param maxDeliveryCount the maxDeliveryCount value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setMaxDeliveryCount(int maxDeliveryCount) {
        description.setMaxDeliveryCount(maxDeliveryCount);
        return this;
    }

    /**
     * Get the enableBatchedOperations property: Value that indicates whether server-side batched operations are
     * enabled.
     *
     * @return the enableBatchedOperations value.
     */
    public boolean isBatchedOperationsEnabled() {
        return toPrimitive(description.isEnableBatchedOperations());
    }

    /**
     * Set the enableBatchedOperations property: Value that indicates whether server-side batched operations are
     * enabled.
     *
     * @param enableBatchedOperations the enableBatchedOperations value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setBatchedOperationsEnabled(boolean enableBatchedOperations) {
        description.setEnableBatchedOperations(enableBatchedOperations);
        return this;
    }

    /**
     * Get the status property: Status of a Service Bus resource.
     *
     * @return the status value.
     */
    public EntityStatus getStatus() {
        return description.getStatus();
    }

    /**
     * Set the status property: Status of a Service Bus resource.
     *
     * @param status the status value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setStatus(EntityStatus status) {
        description.setStatus(status);
        return this;
    }

    /**
     * Get the forwardTo property: The name of the recipient entity to which all the messages sent to the subscription
     * are forwarded to.
     *
     * @return the forwardTo value.
     */
    public String getForwardTo() {
        return description.getForwardTo();
    }

    /**
     * Set the forwardTo property: The name of the recipient entity to which all the messages sent to the subscription
     * are forwarded to.
     *
     * @param forwardTo the forwardTo value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setForwardTo(String forwardTo) {
        description.setForwardTo(forwardTo);
        return this;
    }

    /**
     * Get the createdAt property: The exact time the subscription was created.
     *
     * @return the createdAt value.
     */
    OffsetDateTime getCreatedAt() {
        return description.getCreatedAt();
    }

    /**
     * Get the updatedAt property: The exact time a message was updated in the subscription.
     *
     * @return the updatedAt value.
     */
    OffsetDateTime getUpdatedAt() {
        return description.getUpdatedAt();
    }

    /**
     * Get the accessedAt property: Last time a message was sent, or the last time there was a receive request to this
     * subscription.
     *
     * @return the accessedAt value.
     */
    OffsetDateTime getAccessedAt() {
        return description.getAccessedAt();
    }

    /**
     * Get the messageCountDetails property: Details about the message counts in entity.
     *
     * @return the messageCountDetails value.
     */
    MessageCountDetailsImpl getMessageCountDetails() {
        return description.getMessageCountDetails();
    }

    /**
     * Get the userMetadata property: Metadata associated with the subscription. Maximum number of characters is 1024.
     *
     * @return the userMetadata value.
     */
    public String getUserMetadata() {
        return description.getUserMetadata();
    }

    /**
     * Set the userMetadata property: Metadata associated with the subscription. Maximum number of characters is 1024.
     *
     * @param userMetadata the userMetadata value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setUserMetadata(String userMetadata) {
        description.setUserMetadata(userMetadata);
        return this;
    }

    /**
     * Get the forwardDeadLetteredMessagesTo property: The name of the recipient entity to which all the messages sent
     * to the subscription are forwarded to.
     *
     * @return the forwardDeadLetteredMessagesTo value.
     */
    public String getForwardDeadLetteredMessagesTo() {
        return description.getForwardDeadLetteredMessagesTo();
    }

    /**
     * Set the forwardDeadLetteredMessagesTo property: The name of the recipient entity to which all the messages sent
     * to the subscription are forwarded to.
     *
     * @param forwardDeadLetteredMessagesTo the forwardDeadLetteredMessagesTo value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setForwardDeadLetteredMessagesTo(String forwardDeadLetteredMessagesTo) {
        description.setForwardDeadLetteredMessagesTo(forwardDeadLetteredMessagesTo);
        return this;
    }

    /**
     * Get the autoDeleteOnIdle property: ISO 8601 timeSpan idle interval after which the subscription is automatically
     * deleted. The minimum duration is 5 minutes.
     *
     * @return the autoDeleteOnIdle value.
     */
    public Duration getAutoDeleteOnIdle() {
        return description.getAutoDeleteOnIdle();
    }

    /**
     * Set the autoDeleteOnIdle property: ISO 8601 timeSpan idle interval after which the subscription is automatically
     * deleted. The minimum duration is 5 minutes.
     *
     * @param autoDeleteOnIdle the autoDeleteOnIdle value to set.
     * @return the SubscriptionProperties object itself.
     */
    public SubscriptionProperties setAutoDeleteOnIdle(Duration autoDeleteOnIdle) {
        description.setAutoDeleteOnIdle(autoDeleteOnIdle);
        return this;
    }

    /**
     * Get the entityAvailabilityStatus property: Availability status of the entity.
     *
     * @return the entityAvailabilityStatus value.
     */
    EntityAvailabilityStatusImpl getEntityAvailabilityStatus() {
        return description.getEntityAvailabilityStatus();
    }
}
