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

package com.azure.resourcemanager.servicefabric.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;

/** Defines a health policy used to evaluate the health of an application or one of its children entities. */
@Fluent
public final class ArmApplicationHealthPolicy {
    /*
     * Indicates whether warnings are treated with the same severity as errors.
     */
    @JsonProperty(value = "considerWarningAsError")
    private Boolean considerWarningAsError;

    /*
     * The maximum allowed percentage of unhealthy deployed applications. Allowed values are Byte values from zero to
     * 100.
     * The percentage represents the maximum tolerated percentage of deployed applications that can be unhealthy before
     * the application is considered in error.
     * This is calculated by dividing the number of unhealthy deployed applications over the number of nodes where the
     * application is currently deployed on in the cluster.
     * The computation rounds up to tolerate one failure on small numbers of nodes. Default percentage is zero.
     *
     */
    @JsonProperty(value = "maxPercentUnhealthyDeployedApplications")
    private Integer maxPercentUnhealthyDeployedApplications;

    /*
     * The health policy used by default to evaluate the health of a service type.
     */
    @JsonProperty(value = "defaultServiceTypeHealthPolicy")
    private ArmServiceTypeHealthPolicy defaultServiceTypeHealthPolicy;

    /*
     * The map with service type health policy per service type name. The map is empty by default.
     */
    @JsonProperty(value = "serviceTypeHealthPolicyMap")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.ALWAYS)
    private Map<String, ArmServiceTypeHealthPolicy> serviceTypeHealthPolicyMap;

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

    /**
     * Get the considerWarningAsError property: Indicates whether warnings are treated with the same severity as errors.
     *
     * @return the considerWarningAsError value.
     */
    public Boolean considerWarningAsError() {
        return this.considerWarningAsError;
    }

    /**
     * Set the considerWarningAsError property: Indicates whether warnings are treated with the same severity as errors.
     *
     * @param considerWarningAsError the considerWarningAsError value to set.
     * @return the ArmApplicationHealthPolicy object itself.
     */
    public ArmApplicationHealthPolicy withConsiderWarningAsError(Boolean considerWarningAsError) {
        this.considerWarningAsError = considerWarningAsError;
        return this;
    }

    /**
     * Get the maxPercentUnhealthyDeployedApplications property: The maximum allowed percentage of unhealthy deployed
     * applications. Allowed values are Byte values from zero to 100. The percentage represents the maximum tolerated
     * percentage of deployed applications that can be unhealthy before the application is considered in error. This is
     * calculated by dividing the number of unhealthy deployed applications over the number of nodes where the
     * application is currently deployed on in the cluster. The computation rounds up to tolerate one failure on small
     * numbers of nodes. Default percentage is zero.
     *
     * @return the maxPercentUnhealthyDeployedApplications value.
     */
    public Integer maxPercentUnhealthyDeployedApplications() {
        return this.maxPercentUnhealthyDeployedApplications;
    }

    /**
     * Set the maxPercentUnhealthyDeployedApplications property: The maximum allowed percentage of unhealthy deployed
     * applications. Allowed values are Byte values from zero to 100. The percentage represents the maximum tolerated
     * percentage of deployed applications that can be unhealthy before the application is considered in error. This is
     * calculated by dividing the number of unhealthy deployed applications over the number of nodes where the
     * application is currently deployed on in the cluster. The computation rounds up to tolerate one failure on small
     * numbers of nodes. Default percentage is zero.
     *
     * @param maxPercentUnhealthyDeployedApplications the maxPercentUnhealthyDeployedApplications value to set.
     * @return the ArmApplicationHealthPolicy object itself.
     */
    public ArmApplicationHealthPolicy withMaxPercentUnhealthyDeployedApplications(
        Integer maxPercentUnhealthyDeployedApplications) {
        this.maxPercentUnhealthyDeployedApplications = maxPercentUnhealthyDeployedApplications;
        return this;
    }

    /**
     * Get the defaultServiceTypeHealthPolicy property: The health policy used by default to evaluate the health of a
     * service type.
     *
     * @return the defaultServiceTypeHealthPolicy value.
     */
    public ArmServiceTypeHealthPolicy defaultServiceTypeHealthPolicy() {
        return this.defaultServiceTypeHealthPolicy;
    }

    /**
     * Set the defaultServiceTypeHealthPolicy property: The health policy used by default to evaluate the health of a
     * service type.
     *
     * @param defaultServiceTypeHealthPolicy the defaultServiceTypeHealthPolicy value to set.
     * @return the ArmApplicationHealthPolicy object itself.
     */
    public ArmApplicationHealthPolicy withDefaultServiceTypeHealthPolicy(
        ArmServiceTypeHealthPolicy defaultServiceTypeHealthPolicy) {
        this.defaultServiceTypeHealthPolicy = defaultServiceTypeHealthPolicy;
        return this;
    }

    /**
     * Get the serviceTypeHealthPolicyMap property: The map with service type health policy per service type name. The
     * map is empty by default.
     *
     * @return the serviceTypeHealthPolicyMap value.
     */
    public Map<String, ArmServiceTypeHealthPolicy> serviceTypeHealthPolicyMap() {
        return this.serviceTypeHealthPolicyMap;
    }

    /**
     * Set the serviceTypeHealthPolicyMap property: The map with service type health policy per service type name. The
     * map is empty by default.
     *
     * @param serviceTypeHealthPolicyMap the serviceTypeHealthPolicyMap value to set.
     * @return the ArmApplicationHealthPolicy object itself.
     */
    public ArmApplicationHealthPolicy withServiceTypeHealthPolicyMap(
        Map<String, ArmServiceTypeHealthPolicy> serviceTypeHealthPolicyMap) {
        this.serviceTypeHealthPolicyMap = serviceTypeHealthPolicyMap;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (defaultServiceTypeHealthPolicy() != null) {
            defaultServiceTypeHealthPolicy().validate();
        }
        if (serviceTypeHealthPolicyMap() != null) {
            serviceTypeHealthPolicyMap()
                .values()
                .forEach(
                    e -> {
                        if (e != null) {
                            e.validate();
                        }
                    });
        }
    }
}
