// 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.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.PostRulesClient;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.PostRulesResourceInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.RuleCounterInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.RuleCounterResetInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.PostRules;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.PostRulesResource;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.RuleCounter;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.RuleCounterReset;

public final class PostRulesImpl implements PostRules {
    private static final ClientLogger LOGGER = new ClientLogger(PostRulesImpl.class);

    private final PostRulesClient innerClient;

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

    public PostRulesImpl(
        PostRulesClient innerClient,
        com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<PostRulesResource> list(String globalRulestackName) {
        PagedIterable<PostRulesResourceInner> inner = this.serviceClient().list(globalRulestackName);
        return Utils.mapPage(inner, inner1 -> new PostRulesResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<PostRulesResource> list(String globalRulestackName, Context context) {
        PagedIterable<PostRulesResourceInner> inner = this.serviceClient().list(globalRulestackName, context);
        return Utils.mapPage(inner, inner1 -> new PostRulesResourceImpl(inner1, this.manager()));
    }

    public Response<PostRulesResource> getWithResponse(String globalRulestackName, String priority, Context context) {
        Response<PostRulesResourceInner> inner =
            this.serviceClient().getWithResponse(globalRulestackName, priority, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new PostRulesResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PostRulesResource get(String globalRulestackName, String priority) {
        PostRulesResourceInner inner = this.serviceClient().get(globalRulestackName, priority);
        if (inner != null) {
            return new PostRulesResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PostRulesResource createOrUpdate(
        String globalRulestackName, String priority, PostRulesResourceInner resource) {
        PostRulesResourceInner inner = this.serviceClient().createOrUpdate(globalRulestackName, priority, resource);
        if (inner != null) {
            return new PostRulesResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PostRulesResource createOrUpdate(
        String globalRulestackName, String priority, PostRulesResourceInner resource, Context context) {
        PostRulesResourceInner inner =
            this.serviceClient().createOrUpdate(globalRulestackName, priority, resource, context);
        if (inner != null) {
            return new PostRulesResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void deleteByResourceGroup(String globalRulestackName, String priority) {
        this.serviceClient().delete(globalRulestackName, priority);
    }

    public void delete(String globalRulestackName, String priority, Context context) {
        this.serviceClient().delete(globalRulestackName, priority, context);
    }

    public Response<RuleCounter> getCountersWithResponse(
        String globalRulestackName, String priority, String firewallName, Context context) {
        Response<RuleCounterInner> inner =
            this.serviceClient().getCountersWithResponse(globalRulestackName, priority, firewallName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RuleCounterImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public RuleCounter getCounters(String globalRulestackName, String priority) {
        RuleCounterInner inner = this.serviceClient().getCounters(globalRulestackName, priority);
        if (inner != null) {
            return new RuleCounterImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> refreshCountersWithResponse(
        String globalRulestackName, String priority, String firewallName, Context context) {
        return this.serviceClient().refreshCountersWithResponse(globalRulestackName, priority, firewallName, context);
    }

    public void refreshCounters(String globalRulestackName, String priority) {
        this.serviceClient().refreshCounters(globalRulestackName, priority);
    }

    public Response<RuleCounterReset> resetCountersWithResponse(
        String globalRulestackName, String priority, String firewallName, Context context) {
        Response<RuleCounterResetInner> inner =
            this.serviceClient().resetCountersWithResponse(globalRulestackName, priority, firewallName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RuleCounterResetImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public RuleCounterReset resetCounters(String globalRulestackName, String priority) {
        RuleCounterResetInner inner = this.serviceClient().resetCounters(globalRulestackName, priority);
        if (inner != null) {
            return new RuleCounterResetImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    private PostRulesClient serviceClient() {
        return this.innerClient;
    }

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