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

package com.azure.resourcemanager.paloaltonetworks.ngfw.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.LocalRulesResourceInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ActionEnum;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.BooleanEnum;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.Category;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.DecryptionRuleTypeEnum;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.DestinationAddr;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.LocalRulesResource;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ProvisioningState;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.RuleCounter;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.RuleCounterReset;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SourceAddr;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.StateEnum;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.TagInfo;
import java.util.Collections;
import java.util.List;

public final class LocalRulesResourceImpl
    implements LocalRulesResource, LocalRulesResource.Definition, LocalRulesResource.Update {
    private LocalRulesResourceInner innerObject;

    private final com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

    public String etag() {
        return this.innerModel().etag();
    }

    public String ruleName() {
        return this.innerModel().ruleName();
    }

    public Integer priority() {
        return this.innerModel().priority();
    }

    public String description() {
        return this.innerModel().description();
    }

    public StateEnum ruleState() {
        return this.innerModel().ruleState();
    }

    public SourceAddr source() {
        return this.innerModel().source();
    }

    public BooleanEnum negateSource() {
        return this.innerModel().negateSource();
    }

    public DestinationAddr destination() {
        return this.innerModel().destination();
    }

    public BooleanEnum negateDestination() {
        return this.innerModel().negateDestination();
    }

    public List<String> applications() {
        List<String> inner = this.innerModel().applications();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public Category category() {
        return this.innerModel().category();
    }

    public String protocol() {
        return this.innerModel().protocol();
    }

    public List<String> protocolPortList() {
        List<String> inner = this.innerModel().protocolPortList();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public String inboundInspectionCertificate() {
        return this.innerModel().inboundInspectionCertificate();
    }

    public String auditComment() {
        return this.innerModel().auditComment();
    }

    public ActionEnum actionType() {
        return this.innerModel().actionType();
    }

    public StateEnum enableLogging() {
        return this.innerModel().enableLogging();
    }

    public DecryptionRuleTypeEnum decryptionRuleType() {
        return this.innerModel().decryptionRuleType();
    }

    public List<TagInfo> tags() {
        List<TagInfo> inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public ProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public LocalRulesResourceInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String localRulestackName;

    private String priority;

    public LocalRulesResourceImpl withExistingLocalRulestack(String resourceGroupName, String localRulestackName) {
        this.resourceGroupName = resourceGroupName;
        this.localRulestackName = localRulestackName;
        return this;
    }

    public LocalRulesResource create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLocalRules()
                .createOrUpdate(resourceGroupName, localRulestackName, priority, this.innerModel(), Context.NONE);
        return this;
    }

    public LocalRulesResource create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLocalRules()
                .createOrUpdate(resourceGroupName, localRulestackName, priority, this.innerModel(), context);
        return this;
    }

    LocalRulesResourceImpl(
        String name, com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager serviceManager) {
        this.innerObject = new LocalRulesResourceInner();
        this.serviceManager = serviceManager;
        this.priority = name;
    }

    public LocalRulesResourceImpl update() {
        return this;
    }

    public LocalRulesResource apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLocalRules()
                .createOrUpdate(resourceGroupName, localRulestackName, priority, this.innerModel(), Context.NONE);
        return this;
    }

    public LocalRulesResource apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLocalRules()
                .createOrUpdate(resourceGroupName, localRulestackName, priority, this.innerModel(), context);
        return this;
    }

    LocalRulesResourceImpl(
        LocalRulesResourceInner innerObject,
        com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.localRulestackName = Utils.getValueFromIdByName(innerObject.id(), "localRulestacks");
        this.priority = Utils.getValueFromIdByName(innerObject.id(), "localRules");
    }

    public LocalRulesResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLocalRules()
                .getWithResponse(resourceGroupName, localRulestackName, priority, Context.NONE)
                .getValue();
        return this;
    }

    public LocalRulesResource refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLocalRules()
                .getWithResponse(resourceGroupName, localRulestackName, priority, context)
                .getValue();
        return this;
    }

    public Response<RuleCounter> getCountersWithResponse(String firewallName, Context context) {
        return serviceManager
            .localRules()
            .getCountersWithResponse(resourceGroupName, localRulestackName, priority, firewallName, context);
    }

    public RuleCounter getCounters() {
        return serviceManager.localRules().getCounters(resourceGroupName, localRulestackName, priority);
    }

    public Response<Void> refreshCountersWithResponse(String firewallName, Context context) {
        return serviceManager
            .localRules()
            .refreshCountersWithResponse(resourceGroupName, localRulestackName, priority, firewallName, context);
    }

    public void refreshCounters() {
        serviceManager.localRules().refreshCounters(resourceGroupName, localRulestackName, priority);
    }

    public Response<RuleCounterReset> resetCountersWithResponse(String firewallName, Context context) {
        return serviceManager
            .localRules()
            .resetCountersWithResponse(resourceGroupName, localRulestackName, priority, firewallName, context);
    }

    public RuleCounterReset resetCounters() {
        return serviceManager.localRules().resetCounters(resourceGroupName, localRulestackName, priority);
    }

    public LocalRulesResourceImpl withRuleName(String ruleName) {
        this.innerModel().withRuleName(ruleName);
        return this;
    }

    public LocalRulesResourceImpl withTags(List<TagInfo> tags) {
        this.innerModel().withTags(tags);
        return this;
    }

    public LocalRulesResourceImpl withEtag(String etag) {
        this.innerModel().withEtag(etag);
        return this;
    }

    public LocalRulesResourceImpl withDescription(String description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public LocalRulesResourceImpl withRuleState(StateEnum ruleState) {
        this.innerModel().withRuleState(ruleState);
        return this;
    }

    public LocalRulesResourceImpl withSource(SourceAddr source) {
        this.innerModel().withSource(source);
        return this;
    }

    public LocalRulesResourceImpl withNegateSource(BooleanEnum negateSource) {
        this.innerModel().withNegateSource(negateSource);
        return this;
    }

    public LocalRulesResourceImpl withDestination(DestinationAddr destination) {
        this.innerModel().withDestination(destination);
        return this;
    }

    public LocalRulesResourceImpl withNegateDestination(BooleanEnum negateDestination) {
        this.innerModel().withNegateDestination(negateDestination);
        return this;
    }

    public LocalRulesResourceImpl withApplications(List<String> applications) {
        this.innerModel().withApplications(applications);
        return this;
    }

    public LocalRulesResourceImpl withCategory(Category category) {
        this.innerModel().withCategory(category);
        return this;
    }

    public LocalRulesResourceImpl withProtocol(String protocol) {
        this.innerModel().withProtocol(protocol);
        return this;
    }

    public LocalRulesResourceImpl withProtocolPortList(List<String> protocolPortList) {
        this.innerModel().withProtocolPortList(protocolPortList);
        return this;
    }

    public LocalRulesResourceImpl withInboundInspectionCertificate(String inboundInspectionCertificate) {
        this.innerModel().withInboundInspectionCertificate(inboundInspectionCertificate);
        return this;
    }

    public LocalRulesResourceImpl withAuditComment(String auditComment) {
        this.innerModel().withAuditComment(auditComment);
        return this;
    }

    public LocalRulesResourceImpl withActionType(ActionEnum actionType) {
        this.innerModel().withActionType(actionType);
        return this;
    }

    public LocalRulesResourceImpl withEnableLogging(StateEnum enableLogging) {
        this.innerModel().withEnableLogging(enableLogging);
        return this;
    }

    public LocalRulesResourceImpl withDecryptionRuleType(DecryptionRuleTypeEnum decryptionRuleType) {
        this.innerModel().withDecryptionRuleType(decryptionRuleType);
        return this;
    }
}
