// 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 ApplicationHealthPolicy {
    /*
     * The health policy used by default to evaluate the health of a service type.
     */
    @JsonProperty(value = "defaultServiceTypeHealthPolicy")
    private ServiceTypeHealthPolicy defaultServiceTypeHealthPolicy;

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

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

    /**
     * Get the defaultServiceTypeHealthPolicy property: The health policy used by default to evaluate the health of a
     * service type.
     *
     * @return the defaultServiceTypeHealthPolicy value.
     */
    public ServiceTypeHealthPolicy 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 ApplicationHealthPolicy object itself.
     */
    public ApplicationHealthPolicy withDefaultServiceTypeHealthPolicy(
        ServiceTypeHealthPolicy defaultServiceTypeHealthPolicy) {
        this.defaultServiceTypeHealthPolicy = defaultServiceTypeHealthPolicy;
        return this;
    }

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

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

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