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

package com.azure.resourcemanager.providerhub.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.providerhub.fluent.SkusClient;
import com.azure.resourcemanager.providerhub.fluent.models.SkuResourceInner;
import com.azure.resourcemanager.providerhub.models.SkuResource;
import com.azure.resourcemanager.providerhub.models.Skus;

public final class SkusImpl implements Skus {
    private static final ClientLogger LOGGER = new ClientLogger(SkusImpl.class);

    private final SkusClient innerClient;

    private final com.azure.resourcemanager.providerhub.ProviderHubManager serviceManager;

    public SkusImpl(SkusClient innerClient, com.azure.resourcemanager.providerhub.ProviderHubManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<SkuResource> getWithResponse(
        String providerNamespace, String resourceType, String sku, Context context) {
        Response<SkuResourceInner> inner =
            this.serviceClient().getWithResponse(providerNamespace, resourceType, sku, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuResource get(String providerNamespace, String resourceType, String sku) {
        SkuResourceInner inner = this.serviceClient().get(providerNamespace, resourceType, sku);
        if (inner != null) {
            return new SkuResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteWithResponse(
        String providerNamespace, String resourceType, String sku, Context context) {
        return this.serviceClient().deleteWithResponse(providerNamespace, resourceType, sku, context);
    }

    public void delete(String providerNamespace, String resourceType, String sku) {
        this.serviceClient().delete(providerNamespace, resourceType, sku);
    }

    public Response<SkuResource> getNestedResourceTypeFirstWithResponse(
        String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku, Context context) {
        Response<SkuResourceInner> inner =
            this
                .serviceClient()
                .getNestedResourceTypeFirstWithResponse(
                    providerNamespace, resourceType, nestedResourceTypeFirst, sku, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuResource getNestedResourceTypeFirst(
        String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku) {
        SkuResourceInner inner =
            this
                .serviceClient()
                .getNestedResourceTypeFirst(providerNamespace, resourceType, nestedResourceTypeFirst, sku);
        if (inner != null) {
            return new SkuResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SkuResource> createOrUpdateNestedResourceTypeFirstWithResponse(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String sku,
        SkuResourceInner properties,
        Context context) {
        Response<SkuResourceInner> inner =
            this
                .serviceClient()
                .createOrUpdateNestedResourceTypeFirstWithResponse(
                    providerNamespace, resourceType, nestedResourceTypeFirst, sku, properties, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuResource createOrUpdateNestedResourceTypeFirst(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String sku,
        SkuResourceInner properties) {
        SkuResourceInner inner =
            this
                .serviceClient()
                .createOrUpdateNestedResourceTypeFirst(
                    providerNamespace, resourceType, nestedResourceTypeFirst, sku, properties);
        if (inner != null) {
            return new SkuResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteNestedResourceTypeFirstWithResponse(
        String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku, Context context) {
        return this
            .serviceClient()
            .deleteNestedResourceTypeFirstWithResponse(
                providerNamespace, resourceType, nestedResourceTypeFirst, sku, context);
    }

    public void deleteNestedResourceTypeFirst(
        String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku) {
        this
            .serviceClient()
            .deleteNestedResourceTypeFirst(providerNamespace, resourceType, nestedResourceTypeFirst, sku);
    }

    public Response<SkuResource> getNestedResourceTypeSecondWithResponse(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String sku,
        Context context) {
        Response<SkuResourceInner> inner =
            this
                .serviceClient()
                .getNestedResourceTypeSecondWithResponse(
                    providerNamespace, resourceType, nestedResourceTypeFirst, nestedResourceTypeSecond, sku, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuResource getNestedResourceTypeSecond(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String sku) {
        SkuResourceInner inner =
            this
                .serviceClient()
                .getNestedResourceTypeSecond(
                    providerNamespace, resourceType, nestedResourceTypeFirst, nestedResourceTypeSecond, sku);
        if (inner != null) {
            return new SkuResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SkuResource> createOrUpdateNestedResourceTypeSecondWithResponse(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String sku,
        SkuResourceInner properties,
        Context context) {
        Response<SkuResourceInner> inner =
            this
                .serviceClient()
                .createOrUpdateNestedResourceTypeSecondWithResponse(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    sku,
                    properties,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuResource createOrUpdateNestedResourceTypeSecond(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String sku,
        SkuResourceInner properties) {
        SkuResourceInner inner =
            this
                .serviceClient()
                .createOrUpdateNestedResourceTypeSecond(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    sku,
                    properties);
        if (inner != null) {
            return new SkuResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteNestedResourceTypeSecondWithResponse(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String sku,
        Context context) {
        return this
            .serviceClient()
            .deleteNestedResourceTypeSecondWithResponse(
                providerNamespace, resourceType, nestedResourceTypeFirst, nestedResourceTypeSecond, sku, context);
    }

    public void deleteNestedResourceTypeSecond(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String sku) {
        this
            .serviceClient()
            .deleteNestedResourceTypeSecond(
                providerNamespace, resourceType, nestedResourceTypeFirst, nestedResourceTypeSecond, sku);
    }

    public Response<SkuResource> getNestedResourceTypeThirdWithResponse(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird,
        String sku,
        Context context) {
        Response<SkuResourceInner> inner =
            this
                .serviceClient()
                .getNestedResourceTypeThirdWithResponse(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    nestedResourceTypeThird,
                    sku,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuResource getNestedResourceTypeThird(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird,
        String sku) {
        SkuResourceInner inner =
            this
                .serviceClient()
                .getNestedResourceTypeThird(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    nestedResourceTypeThird,
                    sku);
        if (inner != null) {
            return new SkuResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SkuResource> createOrUpdateNestedResourceTypeThirdWithResponse(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird,
        String sku,
        SkuResourceInner properties,
        Context context) {
        Response<SkuResourceInner> inner =
            this
                .serviceClient()
                .createOrUpdateNestedResourceTypeThirdWithResponse(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    nestedResourceTypeThird,
                    sku,
                    properties,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuResource createOrUpdateNestedResourceTypeThird(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird,
        String sku,
        SkuResourceInner properties) {
        SkuResourceInner inner =
            this
                .serviceClient()
                .createOrUpdateNestedResourceTypeThird(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    nestedResourceTypeThird,
                    sku,
                    properties);
        if (inner != null) {
            return new SkuResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteNestedResourceTypeThirdWithResponse(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird,
        String sku,
        Context context) {
        return this
            .serviceClient()
            .deleteNestedResourceTypeThirdWithResponse(
                providerNamespace,
                resourceType,
                nestedResourceTypeFirst,
                nestedResourceTypeSecond,
                nestedResourceTypeThird,
                sku,
                context);
    }

    public void deleteNestedResourceTypeThird(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird,
        String sku) {
        this
            .serviceClient()
            .deleteNestedResourceTypeThird(
                providerNamespace,
                resourceType,
                nestedResourceTypeFirst,
                nestedResourceTypeSecond,
                nestedResourceTypeThird,
                sku);
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrations(String providerNamespace, String resourceType) {
        PagedIterable<SkuResourceInner> inner =
            this.serviceClient().listByResourceTypeRegistrations(providerNamespace, resourceType);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrations(
        String providerNamespace, String resourceType, Context context) {
        PagedIterable<SkuResourceInner> inner =
            this.serviceClient().listByResourceTypeRegistrations(providerNamespace, resourceType, context);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrationsNestedResourceTypeFirst(
        String providerNamespace, String resourceType, String nestedResourceTypeFirst) {
        PagedIterable<SkuResourceInner> inner =
            this
                .serviceClient()
                .listByResourceTypeRegistrationsNestedResourceTypeFirst(
                    providerNamespace, resourceType, nestedResourceTypeFirst);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrationsNestedResourceTypeFirst(
        String providerNamespace, String resourceType, String nestedResourceTypeFirst, Context context) {
        PagedIterable<SkuResourceInner> inner =
            this
                .serviceClient()
                .listByResourceTypeRegistrationsNestedResourceTypeFirst(
                    providerNamespace, resourceType, nestedResourceTypeFirst, context);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrationsNestedResourceTypeSecond(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond) {
        PagedIterable<SkuResourceInner> inner =
            this
                .serviceClient()
                .listByResourceTypeRegistrationsNestedResourceTypeSecond(
                    providerNamespace, resourceType, nestedResourceTypeFirst, nestedResourceTypeSecond);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrationsNestedResourceTypeSecond(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        Context context) {
        PagedIterable<SkuResourceInner> inner =
            this
                .serviceClient()
                .listByResourceTypeRegistrationsNestedResourceTypeSecond(
                    providerNamespace, resourceType, nestedResourceTypeFirst, nestedResourceTypeSecond, context);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrationsNestedResourceTypeThird(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird) {
        PagedIterable<SkuResourceInner> inner =
            this
                .serviceClient()
                .listByResourceTypeRegistrationsNestedResourceTypeThird(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    nestedResourceTypeThird);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuResource> listByResourceTypeRegistrationsNestedResourceTypeThird(
        String providerNamespace,
        String resourceType,
        String nestedResourceTypeFirst,
        String nestedResourceTypeSecond,
        String nestedResourceTypeThird,
        Context context) {
        PagedIterable<SkuResourceInner> inner =
            this
                .serviceClient()
                .listByResourceTypeRegistrationsNestedResourceTypeThird(
                    providerNamespace,
                    resourceType,
                    nestedResourceTypeFirst,
                    nestedResourceTypeSecond,
                    nestedResourceTypeThird,
                    context);
        return Utils.mapPage(inner, inner1 -> new SkuResourceImpl(inner1, this.manager()));
    }

    public SkuResource getById(String id) {
        String providerNamespace = Utils.getValueFromIdByName(id, "providerRegistrations");
        if (providerNamespace == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.",
                                id)));
        }
        String resourceType = Utils.getValueFromIdByName(id, "resourcetypeRegistrations");
        if (resourceType == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.",
                                id)));
        }
        String sku = Utils.getValueFromIdByName(id, "skus");
        if (sku == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id)));
        }
        return this.getWithResponse(providerNamespace, resourceType, sku, Context.NONE).getValue();
    }

    public Response<SkuResource> getByIdWithResponse(String id, Context context) {
        String providerNamespace = Utils.getValueFromIdByName(id, "providerRegistrations");
        if (providerNamespace == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.",
                                id)));
        }
        String resourceType = Utils.getValueFromIdByName(id, "resourcetypeRegistrations");
        if (resourceType == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.",
                                id)));
        }
        String sku = Utils.getValueFromIdByName(id, "skus");
        if (sku == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id)));
        }
        return this.getWithResponse(providerNamespace, resourceType, sku, context);
    }

    public void deleteById(String id) {
        String providerNamespace = Utils.getValueFromIdByName(id, "providerRegistrations");
        if (providerNamespace == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.",
                                id)));
        }
        String resourceType = Utils.getValueFromIdByName(id, "resourcetypeRegistrations");
        if (resourceType == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.",
                                id)));
        }
        String sku = Utils.getValueFromIdByName(id, "skus");
        if (sku == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id)));
        }
        this.deleteWithResponse(providerNamespace, resourceType, sku, Context.NONE);
    }

    public Response<Void> deleteByIdWithResponse(String id, Context context) {
        String providerNamespace = Utils.getValueFromIdByName(id, "providerRegistrations");
        if (providerNamespace == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.",
                                id)));
        }
        String resourceType = Utils.getValueFromIdByName(id, "resourcetypeRegistrations");
        if (resourceType == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.",
                                id)));
        }
        String sku = Utils.getValueFromIdByName(id, "skus");
        if (sku == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id)));
        }
        return this.deleteWithResponse(providerNamespace, resourceType, sku, context);
    }

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

    private com.azure.resourcemanager.providerhub.ProviderHubManager manager() {
        return this.serviceManager;
    }

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