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

package com.azure.resourcemanager.timeseriesinsights.models;

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

/** Properties of the IoTHub event source. */
@Fluent
public class IoTHubEventSourceCommonProperties extends AzureEventSourceProperties {
    /*
     * The name of the iot hub.
     */
    @JsonProperty(value = "iotHubName", required = true)
    private String iotHubName;

    /*
     * The name of the iot hub's consumer group that holds the partitions from which events will be read.
     */
    @JsonProperty(value = "consumerGroupName", required = true)
    private String consumerGroupName;

    /*
     * The name of the Shared Access Policy key that grants the Time Series Insights service access to the iot hub.
     * This shared access policy key must grant 'service connect' permissions to the iot hub.
     */
    @JsonProperty(value = "keyName", required = true)
    private String keyName;

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

    /**
     * Get the iotHubName property: The name of the iot hub.
     *
     * @return the iotHubName value.
     */
    public String iotHubName() {
        return this.iotHubName;
    }

    /**
     * Set the iotHubName property: The name of the iot hub.
     *
     * @param iotHubName the iotHubName value to set.
     * @return the IoTHubEventSourceCommonProperties object itself.
     */
    public IoTHubEventSourceCommonProperties withIotHubName(String iotHubName) {
        this.iotHubName = iotHubName;
        return this;
    }

    /**
     * Get the consumerGroupName property: The name of the iot hub's consumer group that holds the partitions from which
     * events will be read.
     *
     * @return the consumerGroupName value.
     */
    public String consumerGroupName() {
        return this.consumerGroupName;
    }

    /**
     * Set the consumerGroupName property: The name of the iot hub's consumer group that holds the partitions from which
     * events will be read.
     *
     * @param consumerGroupName the consumerGroupName value to set.
     * @return the IoTHubEventSourceCommonProperties object itself.
     */
    public IoTHubEventSourceCommonProperties withConsumerGroupName(String consumerGroupName) {
        this.consumerGroupName = consumerGroupName;
        return this;
    }

    /**
     * Get the keyName property: The name of the Shared Access Policy key that grants the Time Series Insights service
     * access to the iot hub. This shared access policy key must grant 'service connect' permissions to the iot hub.
     *
     * @return the keyName value.
     */
    public String keyName() {
        return this.keyName;
    }

    /**
     * Set the keyName property: The name of the Shared Access Policy key that grants the Time Series Insights service
     * access to the iot hub. This shared access policy key must grant 'service connect' permissions to the iot hub.
     *
     * @param keyName the keyName value to set.
     * @return the IoTHubEventSourceCommonProperties object itself.
     */
    public IoTHubEventSourceCommonProperties withKeyName(String keyName) {
        this.keyName = keyName;
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public IoTHubEventSourceCommonProperties withEventSourceResourceId(String eventSourceResourceId) {
        super.withEventSourceResourceId(eventSourceResourceId);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public IoTHubEventSourceCommonProperties withTimestampPropertyName(String timestampPropertyName) {
        super.withTimestampPropertyName(timestampPropertyName);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public IoTHubEventSourceCommonProperties withLocalTimestamp(LocalTimestamp localTimestamp) {
        super.withLocalTimestamp(localTimestamp);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public IoTHubEventSourceCommonProperties withType(IngressStartAtType type) {
        super.withType(type);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public IoTHubEventSourceCommonProperties withTime(String time) {
        super.withTime(time);
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        super.validate();
        if (iotHubName() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property iotHubName in model IoTHubEventSourceCommonProperties"));
        }
        if (consumerGroupName() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property consumerGroupName in model IoTHubEventSourceCommonProperties"));
        }
        if (keyName() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property keyName in model IoTHubEventSourceCommonProperties"));
        }
    }

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