// 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.LocalRulestacksClient;
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.ListAppIdResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.ListFirewallsResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.LocalRulestackResourceInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.PredefinedUrlCategoriesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.SecurityServicesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.SupportInfoInner;
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.ListAppIdResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ListFirewallsResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.LocalRulestackResource;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.LocalRulestacks;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.PredefinedUrlCategoriesResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SecurityServicesResponse;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SecurityServicesTypeEnum;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SupportInfo;

public final class LocalRulestacksImpl implements LocalRulestacks {
    private static final ClientLogger LOGGER = new ClientLogger(LocalRulestacksImpl.class);

    private final LocalRulestacksClient innerClient;

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

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

    public PagedIterable<LocalRulestackResource> list() {
        PagedIterable<LocalRulestackResourceInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new LocalRulestackResourceImpl(inner1, this.manager()));
    }

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

    public PagedIterable<LocalRulestackResource> listByResourceGroup(String resourceGroupName) {
        PagedIterable<LocalRulestackResourceInner> inner = this.serviceClient().listByResourceGroup(resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new LocalRulestackResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<LocalRulestackResource> listByResourceGroup(String resourceGroupName, Context context) {
        PagedIterable<LocalRulestackResourceInner> inner =
            this.serviceClient().listByResourceGroup(resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new LocalRulestackResourceImpl(inner1, this.manager()));
    }

    public Response<LocalRulestackResource> getByResourceGroupWithResponse(
        String resourceGroupName, String localRulestackName, Context context) {
        Response<LocalRulestackResourceInner> inner =
            this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, localRulestackName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new LocalRulestackResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public LocalRulestackResource getByResourceGroup(String resourceGroupName, String localRulestackName) {
        LocalRulestackResourceInner inner =
            this.serviceClient().getByResourceGroup(resourceGroupName, localRulestackName);
        if (inner != null) {
            return new LocalRulestackResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void deleteByResourceGroup(String resourceGroupName, String localRulestackName) {
        this.serviceClient().delete(resourceGroupName, localRulestackName);
    }

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

    public void commit(String resourceGroupName, String localRulestackName) {
        this.serviceClient().commit(resourceGroupName, localRulestackName);
    }

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

    public Response<Changelog> getChangeLogWithResponse(
        String resourceGroupName, String localRulestackName, Context context) {
        Response<ChangelogInner> inner =
            this.serviceClient().getChangeLogWithResponse(resourceGroupName, localRulestackName, 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 resourceGroupName, String localRulestackName) {
        ChangelogInner inner = this.serviceClient().getChangeLog(resourceGroupName, localRulestackName);
        if (inner != null) {
            return new ChangelogImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SupportInfo> getSupportInfoWithResponse(
        String resourceGroupName, String localRulestackName, String email, Context context) {
        Response<SupportInfoInner> inner =
            this.serviceClient().getSupportInfoWithResponse(resourceGroupName, localRulestackName, email, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SupportInfoImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SupportInfo getSupportInfo(String resourceGroupName, String localRulestackName) {
        SupportInfoInner inner = this.serviceClient().getSupportInfo(resourceGroupName, localRulestackName);
        if (inner != null) {
            return new SupportInfoImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<AdvSecurityObjectListResponse> listAdvancedSecurityObjectsWithResponse(
        String resourceGroupName,
        String localRulestackName,
        AdvSecurityObjectTypeEnum type,
        String skip,
        Integer top,
        Context context) {
        Response<AdvSecurityObjectListResponseInner> inner =
            this
                .serviceClient()
                .listAdvancedSecurityObjectsWithResponse(
                    resourceGroupName, localRulestackName, 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 resourceGroupName, String localRulestackName, AdvSecurityObjectTypeEnum type) {
        AdvSecurityObjectListResponseInner inner =
            this.serviceClient().listAdvancedSecurityObjects(resourceGroupName, localRulestackName, type);
        if (inner != null) {
            return new AdvSecurityObjectListResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ListAppIdResponse> listAppIdsWithResponse(
        String resourceGroupName,
        String localRulestackName,
        String appIdVersion,
        String appPrefix,
        String skip,
        Integer top,
        Context context) {
        Response<ListAppIdResponseInner> inner =
            this
                .serviceClient()
                .listAppIdsWithResponse(
                    resourceGroupName, localRulestackName, 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 resourceGroupName, String localRulestackName) {
        ListAppIdResponseInner inner = this.serviceClient().listAppIds(resourceGroupName, localRulestackName);
        if (inner != null) {
            return new ListAppIdResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<CountriesResponse> listCountriesWithResponse(
        String resourceGroupName, String localRulestackName, String skip, Integer top, Context context) {
        Response<CountriesResponseInner> inner =
            this.serviceClient().listCountriesWithResponse(resourceGroupName, localRulestackName, 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 resourceGroupName, String localRulestackName) {
        CountriesResponseInner inner = this.serviceClient().listCountries(resourceGroupName, localRulestackName);
        if (inner != null) {
            return new CountriesResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ListFirewallsResponse> listFirewallsWithResponse(
        String resourceGroupName, String localRulestackName, Context context) {
        Response<ListFirewallsResponseInner> inner =
            this.serviceClient().listFirewallsWithResponse(resourceGroupName, localRulestackName, 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 resourceGroupName, String localRulestackName) {
        ListFirewallsResponseInner inner = this.serviceClient().listFirewalls(resourceGroupName, localRulestackName);
        if (inner != null) {
            return new ListFirewallsResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<PredefinedUrlCategoriesResponse> listPredefinedUrlCategoriesWithResponse(
        String resourceGroupName, String localRulestackName, String skip, Integer top, Context context) {
        Response<PredefinedUrlCategoriesResponseInner> inner =
            this
                .serviceClient()
                .listPredefinedUrlCategoriesWithResponse(resourceGroupName, localRulestackName, 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 resourceGroupName, String localRulestackName) {
        PredefinedUrlCategoriesResponseInner inner =
            this.serviceClient().listPredefinedUrlCategories(resourceGroupName, localRulestackName);
        if (inner != null) {
            return new PredefinedUrlCategoriesResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SecurityServicesResponse> listSecurityServicesWithResponse(
        String resourceGroupName,
        String localRulestackName,
        SecurityServicesTypeEnum type,
        String skip,
        Integer top,
        Context context) {
        Response<SecurityServicesResponseInner> inner =
            this
                .serviceClient()
                .listSecurityServicesWithResponse(resourceGroupName, localRulestackName, 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 resourceGroupName, String localRulestackName, SecurityServicesTypeEnum type) {
        SecurityServicesResponseInner inner =
            this.serviceClient().listSecurityServices(resourceGroupName, localRulestackName, type);
        if (inner != null) {
            return new SecurityServicesResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public void revert(String resourceGroupName, String localRulestackName) {
        this.serviceClient().revert(resourceGroupName, localRulestackName);
    }

    public LocalRulestackResource getById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String localRulestackName = Utils.getValueFromIdByName(id, "localRulestacks");
        if (localRulestackName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'localRulestacks'.", id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, localRulestackName, Context.NONE).getValue();
    }

    public Response<LocalRulestackResource> getByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String localRulestackName = Utils.getValueFromIdByName(id, "localRulestacks");
        if (localRulestackName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'localRulestacks'.", id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, localRulestackName, context);
    }

    public void deleteById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String localRulestackName = Utils.getValueFromIdByName(id, "localRulestacks");
        if (localRulestackName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'localRulestacks'.", id)));
        }
        this.delete(resourceGroupName, localRulestackName, Context.NONE);
    }

    public void deleteByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String localRulestackName = Utils.getValueFromIdByName(id, "localRulestacks");
        if (localRulestackName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'localRulestacks'.", id)));
        }
        this.delete(resourceGroupName, localRulestackName, context);
    }

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

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

    public LocalRulestackResourceImpl define(String name) {
        return new LocalRulestackResourceImpl(name, this.manager());
    }
}
