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

package com.azure.resourcemanager.dataprotection.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;
import java.util.List;

/** Restore target info for Item level restore operation. */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "objectType")
@JsonTypeName("ItemLevelRestoreTargetInfo")
@Fluent
public final class ItemLevelRestoreTargetInfo extends RestoreTargetInfoBase {
    /*
     * Restore Criteria
     */
    @JsonProperty(value = "restoreCriteria", required = true)
    private List<ItemLevelRestoreCriteria> restoreCriteria;

    /*
     * Datasource
     *
     * Information of target DS
     */
    @JsonProperty(value = "datasourceInfo", required = true)
    private Datasource datasourceInfo;

    /*
     * DatasourceSet
     *
     * Information of target DS Set
     */
    @JsonProperty(value = "datasourceSetInfo")
    private DatasourceSet datasourceSetInfo;

    /*
     * Credentials to use to authenticate with data source provider.
     */
    @JsonProperty(value = "datasourceAuthCredentials")
    private AuthCredentials datasourceAuthCredentials;

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

    /**
     * Get the restoreCriteria property: Restore Criteria.
     *
     * @return the restoreCriteria value.
     */
    public List<ItemLevelRestoreCriteria> restoreCriteria() {
        return this.restoreCriteria;
    }

    /**
     * Set the restoreCriteria property: Restore Criteria.
     *
     * @param restoreCriteria the restoreCriteria value to set.
     * @return the ItemLevelRestoreTargetInfo object itself.
     */
    public ItemLevelRestoreTargetInfo withRestoreCriteria(List<ItemLevelRestoreCriteria> restoreCriteria) {
        this.restoreCriteria = restoreCriteria;
        return this;
    }

    /**
     * Get the datasourceInfo property: Datasource
     *
     * <p>Information of target DS.
     *
     * @return the datasourceInfo value.
     */
    public Datasource datasourceInfo() {
        return this.datasourceInfo;
    }

    /**
     * Set the datasourceInfo property: Datasource
     *
     * <p>Information of target DS.
     *
     * @param datasourceInfo the datasourceInfo value to set.
     * @return the ItemLevelRestoreTargetInfo object itself.
     */
    public ItemLevelRestoreTargetInfo withDatasourceInfo(Datasource datasourceInfo) {
        this.datasourceInfo = datasourceInfo;
        return this;
    }

    /**
     * Get the datasourceSetInfo property: DatasourceSet
     *
     * <p>Information of target DS Set.
     *
     * @return the datasourceSetInfo value.
     */
    public DatasourceSet datasourceSetInfo() {
        return this.datasourceSetInfo;
    }

    /**
     * Set the datasourceSetInfo property: DatasourceSet
     *
     * <p>Information of target DS Set.
     *
     * @param datasourceSetInfo the datasourceSetInfo value to set.
     * @return the ItemLevelRestoreTargetInfo object itself.
     */
    public ItemLevelRestoreTargetInfo withDatasourceSetInfo(DatasourceSet datasourceSetInfo) {
        this.datasourceSetInfo = datasourceSetInfo;
        return this;
    }

    /**
     * Get the datasourceAuthCredentials property: Credentials to use to authenticate with data source provider.
     *
     * @return the datasourceAuthCredentials value.
     */
    public AuthCredentials datasourceAuthCredentials() {
        return this.datasourceAuthCredentials;
    }

    /**
     * Set the datasourceAuthCredentials property: Credentials to use to authenticate with data source provider.
     *
     * @param datasourceAuthCredentials the datasourceAuthCredentials value to set.
     * @return the ItemLevelRestoreTargetInfo object itself.
     */
    public ItemLevelRestoreTargetInfo withDatasourceAuthCredentials(AuthCredentials datasourceAuthCredentials) {
        this.datasourceAuthCredentials = datasourceAuthCredentials;
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public ItemLevelRestoreTargetInfo withRecoveryOption(RecoveryOption recoveryOption) {
        super.withRecoveryOption(recoveryOption);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public ItemLevelRestoreTargetInfo withRestoreLocation(String restoreLocation) {
        super.withRestoreLocation(restoreLocation);
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        super.validate();
        if (restoreCriteria() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property restoreCriteria in model ItemLevelRestoreTargetInfo"));
        } else {
            restoreCriteria().forEach(e -> e.validate());
        }
        if (datasourceInfo() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property datasourceInfo in model ItemLevelRestoreTargetInfo"));
        } else {
            datasourceInfo().validate();
        }
        if (datasourceSetInfo() != null) {
            datasourceSetInfo().validate();
        }
        if (datasourceAuthCredentials() != null) {
            datasourceAuthCredentials().validate();
        }
    }

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