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

package com.azure.resourcemanager.iothub.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;

/** The properties related to a cosmos DB sql collection endpoint. */
@Fluent
public final class RoutingCosmosDBSqlApiProperties {
    /*
     * The name that identifies this endpoint. The name can only include alphanumeric characters, periods, underscores,
     * hyphens and has a maximum length of 64 characters. The following names are reserved:  events, fileNotifications,
     * $default. Endpoint names must be unique across endpoint types.
     */
    @JsonProperty(value = "name", required = true)
    private String name;

    /*
     * Id of the cosmos DB sql collection endpoint
     */
    @JsonProperty(value = "id")
    private String id;

    /*
     * The subscription identifier of the cosmos DB account.
     */
    @JsonProperty(value = "subscriptionId")
    private String subscriptionId;

    /*
     * The name of the resource group of the cosmos DB account.
     */
    @JsonProperty(value = "resourceGroup")
    private String resourceGroup;

    /*
     * The url of the cosmos DB account. It must include the protocol https://
     */
    @JsonProperty(value = "endpointUri", required = true)
    private String endpointUri;

    /*
     * Method used to authenticate against the cosmos DB sql collection endpoint
     */
    @JsonProperty(value = "authenticationType")
    private AuthenticationType authenticationType;

    /*
     * Managed identity properties of routing cosmos DB collection endpoint.
     */
    @JsonProperty(value = "identity")
    private ManagedIdentity identity;

    /*
     * The primary key of the cosmos DB account.
     */
    @JsonProperty(value = "primaryKey")
    private String primaryKey;

    /*
     * The secondary key of the cosmos DB account.
     */
    @JsonProperty(value = "secondaryKey")
    private String secondaryKey;

    /*
     * The name of the cosmos DB database in the cosmos DB account.
     */
    @JsonProperty(value = "databaseName", required = true)
    private String databaseName;

    /*
     * The name of the cosmos DB sql collection in the cosmos DB database.
     */
    @JsonProperty(value = "collectionName", required = true)
    private String collectionName;

    /*
     * The name of the partition key associated with this cosmos DB sql collection if one exists. This is an optional
     * parameter.
     */
    @JsonProperty(value = "partitionKeyName")
    private String partitionKeyName;

    /*
     * The template for generating a synthetic partition key value for use with this cosmos DB sql collection. The
     * template must include at least one of the following placeholders: {iothub}, {deviceid}, {DD}, {MM}, and {YYYY}.
     * Any one placeholder may be specified at most once, but order and non-placeholder components are arbitrary. This
     * parameter is only required if PartitionKeyName is specified.
     */
    @JsonProperty(value = "partitionKeyTemplate")
    private String partitionKeyTemplate;

    /** Creates an instance of RoutingCosmosDBSqlApiProperties class. */
    public RoutingCosmosDBSqlApiProperties() {
    }

    /**
     * Get the name property: The name that identifies this endpoint. The name can only include alphanumeric characters,
     * periods, underscores, hyphens and has a maximum length of 64 characters. The following names are reserved:
     * events, fileNotifications, $default. Endpoint names must be unique across endpoint types.
     *
     * @return the name value.
     */
    public String name() {
        return this.name;
    }

    /**
     * Set the name property: The name that identifies this endpoint. The name can only include alphanumeric characters,
     * periods, underscores, hyphens and has a maximum length of 64 characters. The following names are reserved:
     * events, fileNotifications, $default. Endpoint names must be unique across endpoint types.
     *
     * @param name the name value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Get the id property: Id of the cosmos DB sql collection endpoint.
     *
     * @return the id value.
     */
    public String id() {
        return this.id;
    }

    /**
     * Set the id property: Id of the cosmos DB sql collection endpoint.
     *
     * @param id the id value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withId(String id) {
        this.id = id;
        return this;
    }

    /**
     * Get the subscriptionId property: The subscription identifier of the cosmos DB account.
     *
     * @return the subscriptionId value.
     */
    public String subscriptionId() {
        return this.subscriptionId;
    }

    /**
     * Set the subscriptionId property: The subscription identifier of the cosmos DB account.
     *
     * @param subscriptionId the subscriptionId value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withSubscriptionId(String subscriptionId) {
        this.subscriptionId = subscriptionId;
        return this;
    }

    /**
     * Get the resourceGroup property: The name of the resource group of the cosmos DB account.
     *
     * @return the resourceGroup value.
     */
    public String resourceGroup() {
        return this.resourceGroup;
    }

    /**
     * Set the resourceGroup property: The name of the resource group of the cosmos DB account.
     *
     * @param resourceGroup the resourceGroup value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withResourceGroup(String resourceGroup) {
        this.resourceGroup = resourceGroup;
        return this;
    }

    /**
     * Get the endpointUri property: The url of the cosmos DB account. It must include the protocol https://.
     *
     * @return the endpointUri value.
     */
    public String endpointUri() {
        return this.endpointUri;
    }

    /**
     * Set the endpointUri property: The url of the cosmos DB account. It must include the protocol https://.
     *
     * @param endpointUri the endpointUri value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withEndpointUri(String endpointUri) {
        this.endpointUri = endpointUri;
        return this;
    }

    /**
     * Get the authenticationType property: Method used to authenticate against the cosmos DB sql collection endpoint.
     *
     * @return the authenticationType value.
     */
    public AuthenticationType authenticationType() {
        return this.authenticationType;
    }

    /**
     * Set the authenticationType property: Method used to authenticate against the cosmos DB sql collection endpoint.
     *
     * @param authenticationType the authenticationType value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withAuthenticationType(AuthenticationType authenticationType) {
        this.authenticationType = authenticationType;
        return this;
    }

    /**
     * Get the identity property: Managed identity properties of routing cosmos DB collection endpoint.
     *
     * @return the identity value.
     */
    public ManagedIdentity identity() {
        return this.identity;
    }

    /**
     * Set the identity property: Managed identity properties of routing cosmos DB collection endpoint.
     *
     * @param identity the identity value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withIdentity(ManagedIdentity identity) {
        this.identity = identity;
        return this;
    }

    /**
     * Get the primaryKey property: The primary key of the cosmos DB account.
     *
     * @return the primaryKey value.
     */
    public String primaryKey() {
        return this.primaryKey;
    }

    /**
     * Set the primaryKey property: The primary key of the cosmos DB account.
     *
     * @param primaryKey the primaryKey value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withPrimaryKey(String primaryKey) {
        this.primaryKey = primaryKey;
        return this;
    }

    /**
     * Get the secondaryKey property: The secondary key of the cosmos DB account.
     *
     * @return the secondaryKey value.
     */
    public String secondaryKey() {
        return this.secondaryKey;
    }

    /**
     * Set the secondaryKey property: The secondary key of the cosmos DB account.
     *
     * @param secondaryKey the secondaryKey value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withSecondaryKey(String secondaryKey) {
        this.secondaryKey = secondaryKey;
        return this;
    }

    /**
     * Get the databaseName property: The name of the cosmos DB database in the cosmos DB account.
     *
     * @return the databaseName value.
     */
    public String databaseName() {
        return this.databaseName;
    }

    /**
     * Set the databaseName property: The name of the cosmos DB database in the cosmos DB account.
     *
     * @param databaseName the databaseName value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withDatabaseName(String databaseName) {
        this.databaseName = databaseName;
        return this;
    }

    /**
     * Get the collectionName property: The name of the cosmos DB sql collection in the cosmos DB database.
     *
     * @return the collectionName value.
     */
    public String collectionName() {
        return this.collectionName;
    }

    /**
     * Set the collectionName property: The name of the cosmos DB sql collection in the cosmos DB database.
     *
     * @param collectionName the collectionName value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withCollectionName(String collectionName) {
        this.collectionName = collectionName;
        return this;
    }

    /**
     * Get the partitionKeyName property: The name of the partition key associated with this cosmos DB sql collection if
     * one exists. This is an optional parameter.
     *
     * @return the partitionKeyName value.
     */
    public String partitionKeyName() {
        return this.partitionKeyName;
    }

    /**
     * Set the partitionKeyName property: The name of the partition key associated with this cosmos DB sql collection if
     * one exists. This is an optional parameter.
     *
     * @param partitionKeyName the partitionKeyName value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withPartitionKeyName(String partitionKeyName) {
        this.partitionKeyName = partitionKeyName;
        return this;
    }

    /**
     * Get the partitionKeyTemplate property: The template for generating a synthetic partition key value for use with
     * this cosmos DB sql collection. The template must include at least one of the following placeholders: {iothub},
     * {deviceid}, {DD}, {MM}, and {YYYY}. Any one placeholder may be specified at most once, but order and
     * non-placeholder components are arbitrary. This parameter is only required if PartitionKeyName is specified.
     *
     * @return the partitionKeyTemplate value.
     */
    public String partitionKeyTemplate() {
        return this.partitionKeyTemplate;
    }

    /**
     * Set the partitionKeyTemplate property: The template for generating a synthetic partition key value for use with
     * this cosmos DB sql collection. The template must include at least one of the following placeholders: {iothub},
     * {deviceid}, {DD}, {MM}, and {YYYY}. Any one placeholder may be specified at most once, but order and
     * non-placeholder components are arbitrary. This parameter is only required if PartitionKeyName is specified.
     *
     * @param partitionKeyTemplate the partitionKeyTemplate value to set.
     * @return the RoutingCosmosDBSqlApiProperties object itself.
     */
    public RoutingCosmosDBSqlApiProperties withPartitionKeyTemplate(String partitionKeyTemplate) {
        this.partitionKeyTemplate = partitionKeyTemplate;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (name() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property name in model RoutingCosmosDBSqlApiProperties"));
        }
        if (endpointUri() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property endpointUri in model RoutingCosmosDBSqlApiProperties"));
        }
        if (identity() != null) {
            identity().validate();
        }
        if (databaseName() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property databaseName in model RoutingCosmosDBSqlApiProperties"));
        }
        if (collectionName() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property collectionName in model RoutingCosmosDBSqlApiProperties"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(RoutingCosmosDBSqlApiProperties.class);
}
