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

package com.azure.resourcemanager.appcontainers.models;

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

/** Container App Ingress configuration. */
@Fluent
public final class Ingress {
    /*
     * Hostname.
     */
    @JsonProperty(value = "fqdn", access = JsonProperty.Access.WRITE_ONLY)
    private String fqdn;

    /*
     * Bool indicating if app exposes an external http endpoint
     */
    @JsonProperty(value = "external")
    private Boolean external;

    /*
     * Target Port in containers for traffic from ingress
     */
    @JsonProperty(value = "targetPort")
    private Integer targetPort;

    /*
     * Exposed Port in containers for TCP traffic from ingress
     */
    @JsonProperty(value = "exposedPort")
    private Integer exposedPort;

    /*
     * Ingress transport protocol
     */
    @JsonProperty(value = "transport")
    private IngressTransportMethod transport;

    /*
     * Traffic weights for app's revisions
     */
    @JsonProperty(value = "traffic")
    private List<TrafficWeight> traffic;

    /*
     * custom domain bindings for Container Apps' hostnames.
     */
    @JsonProperty(value = "customDomains")
    private List<CustomDomain> customDomains;

    /*
     * Bool indicating if HTTP connections to is allowed. If set to false HTTP connections are automatically redirected
     * to HTTPS connections
     */
    @JsonProperty(value = "allowInsecure")
    private Boolean allowInsecure;

    /*
     * Rules to restrict incoming IP address.
     */
    @JsonProperty(value = "ipSecurityRestrictions")
    private List<IpSecurityRestrictionRule> ipSecurityRestrictions;

    /*
     * Sticky Sessions for Single Revision Mode
     */
    @JsonProperty(value = "stickySessions")
    private IngressStickySessions stickySessions;

    /*
     * Client certificate mode for mTLS authentication. Ignore indicates server drops client certificate on forwarding.
     * Accept indicates server forwards client certificate but does not require a client certificate. Require indicates
     * server requires a client certificate.
     */
    @JsonProperty(value = "clientCertificateMode")
    private IngressClientCertificateMode clientCertificateMode;

    /*
     * CORS policy for container app
     */
    @JsonProperty(value = "corsPolicy")
    private CorsPolicy corsPolicy;

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

    /**
     * Get the fqdn property: Hostname.
     *
     * @return the fqdn value.
     */
    public String fqdn() {
        return this.fqdn;
    }

    /**
     * Get the external property: Bool indicating if app exposes an external http endpoint.
     *
     * @return the external value.
     */
    public Boolean external() {
        return this.external;
    }

    /**
     * Set the external property: Bool indicating if app exposes an external http endpoint.
     *
     * @param external the external value to set.
     * @return the Ingress object itself.
     */
    public Ingress withExternal(Boolean external) {
        this.external = external;
        return this;
    }

    /**
     * Get the targetPort property: Target Port in containers for traffic from ingress.
     *
     * @return the targetPort value.
     */
    public Integer targetPort() {
        return this.targetPort;
    }

    /**
     * Set the targetPort property: Target Port in containers for traffic from ingress.
     *
     * @param targetPort the targetPort value to set.
     * @return the Ingress object itself.
     */
    public Ingress withTargetPort(Integer targetPort) {
        this.targetPort = targetPort;
        return this;
    }

    /**
     * Get the exposedPort property: Exposed Port in containers for TCP traffic from ingress.
     *
     * @return the exposedPort value.
     */
    public Integer exposedPort() {
        return this.exposedPort;
    }

    /**
     * Set the exposedPort property: Exposed Port in containers for TCP traffic from ingress.
     *
     * @param exposedPort the exposedPort value to set.
     * @return the Ingress object itself.
     */
    public Ingress withExposedPort(Integer exposedPort) {
        this.exposedPort = exposedPort;
        return this;
    }

    /**
     * Get the transport property: Ingress transport protocol.
     *
     * @return the transport value.
     */
    public IngressTransportMethod transport() {
        return this.transport;
    }

    /**
     * Set the transport property: Ingress transport protocol.
     *
     * @param transport the transport value to set.
     * @return the Ingress object itself.
     */
    public Ingress withTransport(IngressTransportMethod transport) {
        this.transport = transport;
        return this;
    }

    /**
     * Get the traffic property: Traffic weights for app's revisions.
     *
     * @return the traffic value.
     */
    public List<TrafficWeight> traffic() {
        return this.traffic;
    }

    /**
     * Set the traffic property: Traffic weights for app's revisions.
     *
     * @param traffic the traffic value to set.
     * @return the Ingress object itself.
     */
    public Ingress withTraffic(List<TrafficWeight> traffic) {
        this.traffic = traffic;
        return this;
    }

    /**
     * Get the customDomains property: custom domain bindings for Container Apps' hostnames.
     *
     * @return the customDomains value.
     */
    public List<CustomDomain> customDomains() {
        return this.customDomains;
    }

    /**
     * Set the customDomains property: custom domain bindings for Container Apps' hostnames.
     *
     * @param customDomains the customDomains value to set.
     * @return the Ingress object itself.
     */
    public Ingress withCustomDomains(List<CustomDomain> customDomains) {
        this.customDomains = customDomains;
        return this;
    }

    /**
     * Get the allowInsecure property: Bool indicating if HTTP connections to is allowed. If set to false HTTP
     * connections are automatically redirected to HTTPS connections.
     *
     * @return the allowInsecure value.
     */
    public Boolean allowInsecure() {
        return this.allowInsecure;
    }

    /**
     * Set the allowInsecure property: Bool indicating if HTTP connections to is allowed. If set to false HTTP
     * connections are automatically redirected to HTTPS connections.
     *
     * @param allowInsecure the allowInsecure value to set.
     * @return the Ingress object itself.
     */
    public Ingress withAllowInsecure(Boolean allowInsecure) {
        this.allowInsecure = allowInsecure;
        return this;
    }

    /**
     * Get the ipSecurityRestrictions property: Rules to restrict incoming IP address.
     *
     * @return the ipSecurityRestrictions value.
     */
    public List<IpSecurityRestrictionRule> ipSecurityRestrictions() {
        return this.ipSecurityRestrictions;
    }

    /**
     * Set the ipSecurityRestrictions property: Rules to restrict incoming IP address.
     *
     * @param ipSecurityRestrictions the ipSecurityRestrictions value to set.
     * @return the Ingress object itself.
     */
    public Ingress withIpSecurityRestrictions(List<IpSecurityRestrictionRule> ipSecurityRestrictions) {
        this.ipSecurityRestrictions = ipSecurityRestrictions;
        return this;
    }

    /**
     * Get the stickySessions property: Sticky Sessions for Single Revision Mode.
     *
     * @return the stickySessions value.
     */
    public IngressStickySessions stickySessions() {
        return this.stickySessions;
    }

    /**
     * Set the stickySessions property: Sticky Sessions for Single Revision Mode.
     *
     * @param stickySessions the stickySessions value to set.
     * @return the Ingress object itself.
     */
    public Ingress withStickySessions(IngressStickySessions stickySessions) {
        this.stickySessions = stickySessions;
        return this;
    }

    /**
     * Get the clientCertificateMode property: Client certificate mode for mTLS authentication. Ignore indicates server
     * drops client certificate on forwarding. Accept indicates server forwards client certificate but does not require
     * a client certificate. Require indicates server requires a client certificate.
     *
     * @return the clientCertificateMode value.
     */
    public IngressClientCertificateMode clientCertificateMode() {
        return this.clientCertificateMode;
    }

    /**
     * Set the clientCertificateMode property: Client certificate mode for mTLS authentication. Ignore indicates server
     * drops client certificate on forwarding. Accept indicates server forwards client certificate but does not require
     * a client certificate. Require indicates server requires a client certificate.
     *
     * @param clientCertificateMode the clientCertificateMode value to set.
     * @return the Ingress object itself.
     */
    public Ingress withClientCertificateMode(IngressClientCertificateMode clientCertificateMode) {
        this.clientCertificateMode = clientCertificateMode;
        return this;
    }

    /**
     * Get the corsPolicy property: CORS policy for container app.
     *
     * @return the corsPolicy value.
     */
    public CorsPolicy corsPolicy() {
        return this.corsPolicy;
    }

    /**
     * Set the corsPolicy property: CORS policy for container app.
     *
     * @param corsPolicy the corsPolicy value to set.
     * @return the Ingress object itself.
     */
    public Ingress withCorsPolicy(CorsPolicy corsPolicy) {
        this.corsPolicy = corsPolicy;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (traffic() != null) {
            traffic().forEach(e -> e.validate());
        }
        if (customDomains() != null) {
            customDomains().forEach(e -> e.validate());
        }
        if (ipSecurityRestrictions() != null) {
            ipSecurityRestrictions().forEach(e -> e.validate());
        }
        if (stickySessions() != null) {
            stickySessions().validate();
        }
        if (corsPolicy() != null) {
            corsPolicy().validate();
        }
    }
}
