// 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.GlobalRulestacksClient;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.AdvSecurityObjectListResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.ChangelogInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.CountriesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.GlobalRulestackResourceInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.ListAppIdResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.ListFirewallsResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.PredefinedUrlCategoriesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.SecurityServicesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.AdvSecurityObjectListResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.AdvSecurityObjectTypeEnum;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.Changelog;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.CountriesResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.GlobalRulestackResource;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.GlobalRulestackResourceUpdate;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.GlobalRulestacks;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ListAppIdResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ListFirewallsResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.PredefinedUrlCategoriesResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SecurityServicesResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SecurityServicesTypeEnum;

public final class GlobalRulestacksImpl implements GlobalRulestacks {
    private static final ClientLogger LOGGER = new ClientLogger(GlobalRulestacksImpl.class);

    private final GlobalRulestacksClient innerClient;

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

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

    public PagedIterable<GlobalRulestackResource> list() {
        PagedIterable<GlobalRulestackResourceInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new GlobalRulestackResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<GlobalRulestackResource> list(Context context) {
        PagedIterable<GlobalRulestackResourceInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new GlobalRulestackResourceImpl(inner1, this.manager()));
    }

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

    public GlobalRulestackResource get(String globalRulestackName) {
        GlobalRulestackResourceInner inner = this.serviceClient().get(globalRulestackName);
        if (inner != null) {
            return new GlobalRulestackResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public GlobalRulestackResource createOrUpdate(String globalRulestackName, GlobalRulestackResourceInner resource) {
        GlobalRulestackResourceInner inner = this.serviceClient().createOrUpdate(globalRulestackName, resource);
        if (inner != null) {
            return new GlobalRulestackResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public GlobalRulestackResource createOrUpdate(
        String globalRulestackName, GlobalRulestackResourceInner resource, Context context) {
        GlobalRulestackResourceInner inner =
            this.serviceClient().createOrUpdate(globalRulestackName, resource, context);
        if (inner != null) {
            return new GlobalRulestackResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<GlobalRulestackResource> updateWithResponse(
        String globalRulestackName, GlobalRulestackResourceUpdate properties, Context context) {
        Response<GlobalRulestackResourceInner> inner =
            this.serviceClient().updateWithResponse(globalRulestackName, properties, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new GlobalRulestackResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public GlobalRulestackResource update(String globalRulestackName, GlobalRulestackResourceUpdate properties) {
        GlobalRulestackResourceInner inner = this.serviceClient().update(globalRulestackName, properties);
        if (inner != null) {
            return new GlobalRulestackResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

    public void commit(String globalRulestackName) {
        this.serviceClient().commit(globalRulestackName);
    }

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

    public Response<Changelog> getChangeLogWithResponse(String globalRulestackName, Context context) {
        Response<ChangelogInner> inner = this.serviceClient().getChangeLogWithResponse(globalRulestackName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ChangelogImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Changelog getChangeLog(String globalRulestackName) {
        ChangelogInner inner = this.serviceClient().getChangeLog(globalRulestackName);
        if (inner != null) {
            return new ChangelogImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<AdvSecurityObjectListResponse> listAdvancedSecurityObjectsWithResponse(
        String globalRulestackName, AdvSecurityObjectTypeEnum type, String skip, Integer top, Context context) {
        Response<AdvSecurityObjectListResponseInner> inner =
            this.serviceClient().listAdvancedSecurityObjectsWithResponse(globalRulestackName, type, skip, top, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new AdvSecurityObjectListResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public AdvSecurityObjectListResponse listAdvancedSecurityObjects(
        String globalRulestackName, AdvSecurityObjectTypeEnum type) {
        AdvSecurityObjectListResponseInner inner =
            this.serviceClient().listAdvancedSecurityObjects(globalRulestackName, type);
        if (inner != null) {
            return new AdvSecurityObjectListResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ListAppIdResponse> listAppIdsWithResponse(
        String globalRulestackName, String appIdVersion, String appPrefix, String skip, Integer top, Context context) {
        Response<ListAppIdResponseInner> inner =
            this
                .serviceClient()
                .listAppIdsWithResponse(globalRulestackName, appIdVersion, appPrefix, skip, top, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ListAppIdResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ListAppIdResponse listAppIds(String globalRulestackName) {
        ListAppIdResponseInner inner = this.serviceClient().listAppIds(globalRulestackName);
        if (inner != null) {
            return new ListAppIdResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<CountriesResponse> listCountriesWithResponse(
        String globalRulestackName, String skip, Integer top, Context context) {
        Response<CountriesResponseInner> inner =
            this.serviceClient().listCountriesWithResponse(globalRulestackName, skip, top, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CountriesResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CountriesResponse listCountries(String globalRulestackName) {
        CountriesResponseInner inner = this.serviceClient().listCountries(globalRulestackName);
        if (inner != null) {
            return new CountriesResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ListFirewallsResponse> listFirewallsWithResponse(String globalRulestackName, Context context) {
        Response<ListFirewallsResponseInner> inner =
            this.serviceClient().listFirewallsWithResponse(globalRulestackName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ListFirewallsResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ListFirewallsResponse listFirewalls(String globalRulestackName) {
        ListFirewallsResponseInner inner = this.serviceClient().listFirewalls(globalRulestackName);
        if (inner != null) {
            return new ListFirewallsResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<PredefinedUrlCategoriesResponse> listPredefinedUrlCategoriesWithResponse(
        String globalRulestackName, String skip, Integer top, Context context) {
        Response<PredefinedUrlCategoriesResponseInner> inner =
            this.serviceClient().listPredefinedUrlCategoriesWithResponse(globalRulestackName, skip, top, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new PredefinedUrlCategoriesResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PredefinedUrlCategoriesResponse listPredefinedUrlCategories(String globalRulestackName) {
        PredefinedUrlCategoriesResponseInner inner =
            this.serviceClient().listPredefinedUrlCategories(globalRulestackName);
        if (inner != null) {
            return new PredefinedUrlCategoriesResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SecurityServicesResponse> listSecurityServicesWithResponse(
        String globalRulestackName, SecurityServicesTypeEnum type, String skip, Integer top, Context context) {
        Response<SecurityServicesResponseInner> inner =
            this.serviceClient().listSecurityServicesWithResponse(globalRulestackName, type, skip, top, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SecurityServicesResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SecurityServicesResponse listSecurityServices(String globalRulestackName, SecurityServicesTypeEnum type) {
        SecurityServicesResponseInner inner = this.serviceClient().listSecurityServices(globalRulestackName, type);
        if (inner != null) {
            return new SecurityServicesResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public void revert(String globalRulestackName) {
        this.serviceClient().revert(globalRulestackName);
    }

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

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