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

package com.azure.resourcemanager.batchai.models;

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

/** Credentials to access a container image in a private repository. */
@Fluent
public final class PrivateRegistryCredentials {
    @JsonIgnore private final ClientLogger logger = new ClientLogger(PrivateRegistryCredentials.class);

    /*
     * User name to login to the repository.
     */
    @JsonProperty(value = "username", required = true)
    private String username;

    /*
     * User password to login to the docker repository. One of password or
     * passwordSecretReference must be specified.
     */
    @JsonProperty(value = "password")
    private String password;

    /*
     * KeyVault Secret storing the password. Users can store their secrets in
     * Azure KeyVault and pass it to the Batch AI service to integrate with
     * KeyVault. One of password or passwordSecretReference must be specified.
     */
    @JsonProperty(value = "passwordSecretReference")
    private KeyVaultSecretReference passwordSecretReference;

    /**
     * Get the username property: User name to login to the repository.
     *
     * @return the username value.
     */
    public String username() {
        return this.username;
    }

    /**
     * Set the username property: User name to login to the repository.
     *
     * @param username the username value to set.
     * @return the PrivateRegistryCredentials object itself.
     */
    public PrivateRegistryCredentials withUsername(String username) {
        this.username = username;
        return this;
    }

    /**
     * Get the password property: User password to login to the docker repository. One of password or
     * passwordSecretReference must be specified.
     *
     * @return the password value.
     */
    public String password() {
        return this.password;
    }

    /**
     * Set the password property: User password to login to the docker repository. One of password or
     * passwordSecretReference must be specified.
     *
     * @param password the password value to set.
     * @return the PrivateRegistryCredentials object itself.
     */
    public PrivateRegistryCredentials withPassword(String password) {
        this.password = password;
        return this;
    }

    /**
     * Get the passwordSecretReference property: KeyVault Secret storing the password. Users can store their secrets in
     * Azure KeyVault and pass it to the Batch AI service to integrate with KeyVault. One of password or
     * passwordSecretReference must be specified.
     *
     * @return the passwordSecretReference value.
     */
    public KeyVaultSecretReference passwordSecretReference() {
        return this.passwordSecretReference;
    }

    /**
     * Set the passwordSecretReference property: KeyVault Secret storing the password. Users can store their secrets in
     * Azure KeyVault and pass it to the Batch AI service to integrate with KeyVault. One of password or
     * passwordSecretReference must be specified.
     *
     * @param passwordSecretReference the passwordSecretReference value to set.
     * @return the PrivateRegistryCredentials object itself.
     */
    public PrivateRegistryCredentials withPasswordSecretReference(KeyVaultSecretReference passwordSecretReference) {
        this.passwordSecretReference = passwordSecretReference;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (username() == null) {
            throw logger
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property username in model PrivateRegistryCredentials"));
        }
        if (passwordSecretReference() != null) {
            passwordSecretReference().validate();
        }
    }
}
