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

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

/** Distribute via Azure Compute Gallery. */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonTypeName("SharedImage")
@Fluent
public final class ImageTemplateSharedImageDistributor extends ImageTemplateDistributor {
    /*
     * Resource Id of the Azure Compute Gallery image
     */
    @JsonProperty(value = "galleryImageId", required = true)
    private String galleryImageId;

    /*
     * [Deprecated] A list of regions that the image will be replicated to. This list can be specified only if
     * targetRegions is not specified. This field is deprecated - use targetRegions instead.
     */
    @JsonProperty(value = "replicationRegions")
    private List<String> replicationRegions;

    /*
     * Flag that indicates whether created image version should be excluded from latest. Omit to use the default
     * (false).
     */
    @JsonProperty(value = "excludeFromLatest")
    private Boolean excludeFromLatest;

    /*
     * [Deprecated] Storage account type to be used to store the shared image. Omit to use the default (Standard_LRS).
     * This field can be specified only if replicationRegions is specified. This field is deprecated - use
     * targetRegions instead.
     */
    @JsonProperty(value = "storageAccountType")
    private SharedImageStorageAccountType storageAccountType;

    /*
     * The target regions where the distributed Image Version is going to be replicated to. This object supersedes
     * replicationRegions and can be specified only if replicationRegions is not specified.
     */
    @JsonProperty(value = "targetRegions")
    private List<TargetRegion> targetRegions;

    /*
     * Describes how to generate new x.y.z version number for distribution.
     */
    @JsonProperty(value = "versioning")
    private DistributeVersioner versioning;

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

    /**
     * Get the galleryImageId property: Resource Id of the Azure Compute Gallery image.
     *
     * @return the galleryImageId value.
     */
    public String galleryImageId() {
        return this.galleryImageId;
    }

    /**
     * Set the galleryImageId property: Resource Id of the Azure Compute Gallery image.
     *
     * @param galleryImageId the galleryImageId value to set.
     * @return the ImageTemplateSharedImageDistributor object itself.
     */
    public ImageTemplateSharedImageDistributor withGalleryImageId(String galleryImageId) {
        this.galleryImageId = galleryImageId;
        return this;
    }

    /**
     * Get the replicationRegions property: [Deprecated] A list of regions that the image will be replicated to. This
     * list can be specified only if targetRegions is not specified. This field is deprecated - use targetRegions
     * instead.
     *
     * @return the replicationRegions value.
     */
    public List<String> replicationRegions() {
        return this.replicationRegions;
    }

    /**
     * Set the replicationRegions property: [Deprecated] A list of regions that the image will be replicated to. This
     * list can be specified only if targetRegions is not specified. This field is deprecated - use targetRegions
     * instead.
     *
     * @param replicationRegions the replicationRegions value to set.
     * @return the ImageTemplateSharedImageDistributor object itself.
     */
    public ImageTemplateSharedImageDistributor withReplicationRegions(List<String> replicationRegions) {
        this.replicationRegions = replicationRegions;
        return this;
    }

    /**
     * Get the excludeFromLatest property: Flag that indicates whether created image version should be excluded from
     * latest. Omit to use the default (false).
     *
     * @return the excludeFromLatest value.
     */
    public Boolean excludeFromLatest() {
        return this.excludeFromLatest;
    }

    /**
     * Set the excludeFromLatest property: Flag that indicates whether created image version should be excluded from
     * latest. Omit to use the default (false).
     *
     * @param excludeFromLatest the excludeFromLatest value to set.
     * @return the ImageTemplateSharedImageDistributor object itself.
     */
    public ImageTemplateSharedImageDistributor withExcludeFromLatest(Boolean excludeFromLatest) {
        this.excludeFromLatest = excludeFromLatest;
        return this;
    }

    /**
     * Get the storageAccountType property: [Deprecated] Storage account type to be used to store the shared image. Omit
     * to use the default (Standard_LRS). This field can be specified only if replicationRegions is specified. This
     * field is deprecated - use targetRegions instead.
     *
     * @return the storageAccountType value.
     */
    public SharedImageStorageAccountType storageAccountType() {
        return this.storageAccountType;
    }

    /**
     * Set the storageAccountType property: [Deprecated] Storage account type to be used to store the shared image. Omit
     * to use the default (Standard_LRS). This field can be specified only if replicationRegions is specified. This
     * field is deprecated - use targetRegions instead.
     *
     * @param storageAccountType the storageAccountType value to set.
     * @return the ImageTemplateSharedImageDistributor object itself.
     */
    public ImageTemplateSharedImageDistributor withStorageAccountType(
        SharedImageStorageAccountType storageAccountType) {
        this.storageAccountType = storageAccountType;
        return this;
    }

    /**
     * Get the targetRegions property: The target regions where the distributed Image Version is going to be replicated
     * to. This object supersedes replicationRegions and can be specified only if replicationRegions is not specified.
     *
     * @return the targetRegions value.
     */
    public List<TargetRegion> targetRegions() {
        return this.targetRegions;
    }

    /**
     * Set the targetRegions property: The target regions where the distributed Image Version is going to be replicated
     * to. This object supersedes replicationRegions and can be specified only if replicationRegions is not specified.
     *
     * @param targetRegions the targetRegions value to set.
     * @return the ImageTemplateSharedImageDistributor object itself.
     */
    public ImageTemplateSharedImageDistributor withTargetRegions(List<TargetRegion> targetRegions) {
        this.targetRegions = targetRegions;
        return this;
    }

    /**
     * Get the versioning property: Describes how to generate new x.y.z version number for distribution.
     *
     * @return the versioning value.
     */
    public DistributeVersioner versioning() {
        return this.versioning;
    }

    /**
     * Set the versioning property: Describes how to generate new x.y.z version number for distribution.
     *
     * @param versioning the versioning value to set.
     * @return the ImageTemplateSharedImageDistributor object itself.
     */
    public ImageTemplateSharedImageDistributor withVersioning(DistributeVersioner versioning) {
        this.versioning = versioning;
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public ImageTemplateSharedImageDistributor withRunOutputName(String runOutputName) {
        super.withRunOutputName(runOutputName);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public ImageTemplateSharedImageDistributor withArtifactTags(Map<String, String> artifactTags) {
        super.withArtifactTags(artifactTags);
        return this;
    }

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

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