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

package com.azure.resourcemanager.datamigration.models;

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

/** Information for connecting to SQL database server. */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonTypeName("SqlConnectionInfo")
@Fluent
public final class SqlConnectionInfo extends ConnectionInfo {
    /*
     * Data source in the format Protocol:MachineName\SQLServerInstanceName,PortNumber
     */
    @JsonProperty(value = "dataSource", required = true)
    private String dataSource;

    /*
     * Authentication type to use for connection
     */
    @JsonProperty(value = "authentication")
    private AuthenticationType authentication;

    /*
     * Whether to encrypt the connection
     */
    @JsonProperty(value = "encryptConnection")
    private Boolean encryptConnection;

    /*
     * Additional connection settings
     */
    @JsonProperty(value = "additionalSettings")
    private String additionalSettings;

    /*
     * Whether to trust the server certificate
     */
    @JsonProperty(value = "trustServerCertificate")
    private Boolean trustServerCertificate;

    /*
     * Server platform type for connection
     */
    @JsonProperty(value = "platform")
    private SqlSourcePlatform platform;

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

    /**
     * Get the dataSource property: Data source in the format Protocol:MachineName\SQLServerInstanceName,PortNumber.
     *
     * @return the dataSource value.
     */
    public String dataSource() {
        return this.dataSource;
    }

    /**
     * Set the dataSource property: Data source in the format Protocol:MachineName\SQLServerInstanceName,PortNumber.
     *
     * @param dataSource the dataSource value to set.
     * @return the SqlConnectionInfo object itself.
     */
    public SqlConnectionInfo withDataSource(String dataSource) {
        this.dataSource = dataSource;
        return this;
    }

    /**
     * Get the authentication property: Authentication type to use for connection.
     *
     * @return the authentication value.
     */
    public AuthenticationType authentication() {
        return this.authentication;
    }

    /**
     * Set the authentication property: Authentication type to use for connection.
     *
     * @param authentication the authentication value to set.
     * @return the SqlConnectionInfo object itself.
     */
    public SqlConnectionInfo withAuthentication(AuthenticationType authentication) {
        this.authentication = authentication;
        return this;
    }

    /**
     * Get the encryptConnection property: Whether to encrypt the connection.
     *
     * @return the encryptConnection value.
     */
    public Boolean encryptConnection() {
        return this.encryptConnection;
    }

    /**
     * Set the encryptConnection property: Whether to encrypt the connection.
     *
     * @param encryptConnection the encryptConnection value to set.
     * @return the SqlConnectionInfo object itself.
     */
    public SqlConnectionInfo withEncryptConnection(Boolean encryptConnection) {
        this.encryptConnection = encryptConnection;
        return this;
    }

    /**
     * Get the additionalSettings property: Additional connection settings.
     *
     * @return the additionalSettings value.
     */
    public String additionalSettings() {
        return this.additionalSettings;
    }

    /**
     * Set the additionalSettings property: Additional connection settings.
     *
     * @param additionalSettings the additionalSettings value to set.
     * @return the SqlConnectionInfo object itself.
     */
    public SqlConnectionInfo withAdditionalSettings(String additionalSettings) {
        this.additionalSettings = additionalSettings;
        return this;
    }

    /**
     * Get the trustServerCertificate property: Whether to trust the server certificate.
     *
     * @return the trustServerCertificate value.
     */
    public Boolean trustServerCertificate() {
        return this.trustServerCertificate;
    }

    /**
     * Set the trustServerCertificate property: Whether to trust the server certificate.
     *
     * @param trustServerCertificate the trustServerCertificate value to set.
     * @return the SqlConnectionInfo object itself.
     */
    public SqlConnectionInfo withTrustServerCertificate(Boolean trustServerCertificate) {
        this.trustServerCertificate = trustServerCertificate;
        return this;
    }

    /**
     * Get the platform property: Server platform type for connection.
     *
     * @return the platform value.
     */
    public SqlSourcePlatform platform() {
        return this.platform;
    }

    /**
     * Set the platform property: Server platform type for connection.
     *
     * @param platform the platform value to set.
     * @return the SqlConnectionInfo object itself.
     */
    public SqlConnectionInfo withPlatform(SqlSourcePlatform platform) {
        this.platform = platform;
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public SqlConnectionInfo withUsername(String username) {
        super.withUsername(username);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public SqlConnectionInfo withPassword(String password) {
        super.withPassword(password);
        return this;
    }

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

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