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

package com.azure.resourcemanager.apimanagement.models;

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

/** Custom hostname configuration. */
@Fluent
public final class HostnameConfiguration {
    /*
     * Hostname type.
     */
    @JsonProperty(value = "type", required = true)
    private HostnameType type;

    /*
     * Hostname to configure on the Api Management service.
     */
    @JsonProperty(value = "hostName", required = true)
    private String hostname;

    /*
     * Url to the KeyVault Secret containing the Ssl Certificate. If absolute
     * Url containing version is provided, auto-update of ssl certificate will
     * not work. This requires Api Management service to be configured with
     * aka.ms/apimmsi. The secret should be of type *application/x-pkcs12*
     */
    @JsonProperty(value = "keyVaultId")
    private String keyVaultId;

    /*
     * System or User Assigned Managed identity clientId as generated by Azure
     * AD, which has GET access to the keyVault containing the SSL certificate.
     */
    @JsonProperty(value = "identityClientId")
    private String identityClientId;

    /*
     * Base64 Encoded certificate.
     */
    @JsonProperty(value = "encodedCertificate")
    private String encodedCertificate;

    /*
     * Certificate Password.
     */
    @JsonProperty(value = "certificatePassword")
    private String certificatePassword;

    /*
     * Specify true to setup the certificate associated with this Hostname as
     * the Default SSL Certificate. If a client does not send the SNI header,
     * then this will be the certificate that will be challenged. The property
     * is useful if a service has multiple custom hostname enabled and it needs
     * to decide on the default ssl certificate. The setting only applied to
     * Proxy Hostname Type.
     */
    @JsonProperty(value = "defaultSslBinding")
    private Boolean defaultSslBinding;

    /*
     * Specify true to always negotiate client certificate on the hostname.
     * Default Value is false.
     */
    @JsonProperty(value = "negotiateClientCertificate")
    private Boolean negotiateClientCertificate;

    /*
     * Certificate information.
     */
    @JsonProperty(value = "certificate")
    private CertificateInformation certificate;

    /*
     * Certificate Source.
     */
    @JsonProperty(value = "certificateSource")
    private CertificateSource certificateSource;

    /*
     * Certificate Status.
     */
    @JsonProperty(value = "certificateStatus")
    private CertificateStatus certificateStatus;

    /**
     * Get the type property: Hostname type.
     *
     * @return the type value.
     */
    public HostnameType type() {
        return this.type;
    }

    /**
     * Set the type property: Hostname type.
     *
     * @param type the type value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withType(HostnameType type) {
        this.type = type;
        return this;
    }

    /**
     * Get the hostname property: Hostname to configure on the Api Management service.
     *
     * @return the hostname value.
     */
    public String hostname() {
        return this.hostname;
    }

    /**
     * Set the hostname property: Hostname to configure on the Api Management service.
     *
     * @param hostname the hostname value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withHostname(String hostname) {
        this.hostname = hostname;
        return this;
    }

    /**
     * Get the keyVaultId property: Url to the KeyVault Secret containing the Ssl Certificate. If absolute Url
     * containing version is provided, auto-update of ssl certificate will not work. This requires Api Management
     * service to be configured with aka.ms/apimmsi. The secret should be of type *application/x-pkcs12*.
     *
     * @return the keyVaultId value.
     */
    public String keyVaultId() {
        return this.keyVaultId;
    }

    /**
     * Set the keyVaultId property: Url to the KeyVault Secret containing the Ssl Certificate. If absolute Url
     * containing version is provided, auto-update of ssl certificate will not work. This requires Api Management
     * service to be configured with aka.ms/apimmsi. The secret should be of type *application/x-pkcs12*.
     *
     * @param keyVaultId the keyVaultId value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withKeyVaultId(String keyVaultId) {
        this.keyVaultId = keyVaultId;
        return this;
    }

    /**
     * Get the identityClientId property: System or User Assigned Managed identity clientId as generated by Azure AD,
     * which has GET access to the keyVault containing the SSL certificate.
     *
     * @return the identityClientId value.
     */
    public String identityClientId() {
        return this.identityClientId;
    }

    /**
     * Set the identityClientId property: System or User Assigned Managed identity clientId as generated by Azure AD,
     * which has GET access to the keyVault containing the SSL certificate.
     *
     * @param identityClientId the identityClientId value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withIdentityClientId(String identityClientId) {
        this.identityClientId = identityClientId;
        return this;
    }

    /**
     * Get the encodedCertificate property: Base64 Encoded certificate.
     *
     * @return the encodedCertificate value.
     */
    public String encodedCertificate() {
        return this.encodedCertificate;
    }

    /**
     * Set the encodedCertificate property: Base64 Encoded certificate.
     *
     * @param encodedCertificate the encodedCertificate value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withEncodedCertificate(String encodedCertificate) {
        this.encodedCertificate = encodedCertificate;
        return this;
    }

    /**
     * Get the certificatePassword property: Certificate Password.
     *
     * @return the certificatePassword value.
     */
    public String certificatePassword() {
        return this.certificatePassword;
    }

    /**
     * Set the certificatePassword property: Certificate Password.
     *
     * @param certificatePassword the certificatePassword value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withCertificatePassword(String certificatePassword) {
        this.certificatePassword = certificatePassword;
        return this;
    }

    /**
     * Get the defaultSslBinding property: Specify true to setup the certificate associated with this Hostname as the
     * Default SSL Certificate. If a client does not send the SNI header, then this will be the certificate that will be
     * challenged. The property is useful if a service has multiple custom hostname enabled and it needs to decide on
     * the default ssl certificate. The setting only applied to Proxy Hostname Type.
     *
     * @return the defaultSslBinding value.
     */
    public Boolean defaultSslBinding() {
        return this.defaultSslBinding;
    }

    /**
     * Set the defaultSslBinding property: Specify true to setup the certificate associated with this Hostname as the
     * Default SSL Certificate. If a client does not send the SNI header, then this will be the certificate that will be
     * challenged. The property is useful if a service has multiple custom hostname enabled and it needs to decide on
     * the default ssl certificate. The setting only applied to Proxy Hostname Type.
     *
     * @param defaultSslBinding the defaultSslBinding value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withDefaultSslBinding(Boolean defaultSslBinding) {
        this.defaultSslBinding = defaultSslBinding;
        return this;
    }

    /**
     * Get the negotiateClientCertificate property: Specify true to always negotiate client certificate on the hostname.
     * Default Value is false.
     *
     * @return the negotiateClientCertificate value.
     */
    public Boolean negotiateClientCertificate() {
        return this.negotiateClientCertificate;
    }

    /**
     * Set the negotiateClientCertificate property: Specify true to always negotiate client certificate on the hostname.
     * Default Value is false.
     *
     * @param negotiateClientCertificate the negotiateClientCertificate value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withNegotiateClientCertificate(Boolean negotiateClientCertificate) {
        this.negotiateClientCertificate = negotiateClientCertificate;
        return this;
    }

    /**
     * Get the certificate property: Certificate information.
     *
     * @return the certificate value.
     */
    public CertificateInformation certificate() {
        return this.certificate;
    }

    /**
     * Set the certificate property: Certificate information.
     *
     * @param certificate the certificate value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withCertificate(CertificateInformation certificate) {
        this.certificate = certificate;
        return this;
    }

    /**
     * Get the certificateSource property: Certificate Source.
     *
     * @return the certificateSource value.
     */
    public CertificateSource certificateSource() {
        return this.certificateSource;
    }

    /**
     * Set the certificateSource property: Certificate Source.
     *
     * @param certificateSource the certificateSource value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withCertificateSource(CertificateSource certificateSource) {
        this.certificateSource = certificateSource;
        return this;
    }

    /**
     * Get the certificateStatus property: Certificate Status.
     *
     * @return the certificateStatus value.
     */
    public CertificateStatus certificateStatus() {
        return this.certificateStatus;
    }

    /**
     * Set the certificateStatus property: Certificate Status.
     *
     * @param certificateStatus the certificateStatus value to set.
     * @return the HostnameConfiguration object itself.
     */
    public HostnameConfiguration withCertificateStatus(CertificateStatus certificateStatus) {
        this.certificateStatus = certificateStatus;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (type() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property type in model HostnameConfiguration"));
        }
        if (hostname() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property hostname in model HostnameConfiguration"));
        }
        if (certificate() != null) {
            certificate().validate();
        }
    }

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