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

package com.azure.resourcemanager.hybridnetwork.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.hybridnetwork.fluent.VendorSkusClient;
import com.azure.resourcemanager.hybridnetwork.fluent.models.VendorSkuInner;
import com.azure.resourcemanager.hybridnetwork.models.VendorSku;
import com.azure.resourcemanager.hybridnetwork.models.VendorSkus;

public final class VendorSkusImpl implements VendorSkus {
    private static final ClientLogger LOGGER = new ClientLogger(VendorSkusImpl.class);

    private final VendorSkusClient innerClient;

    private final com.azure.resourcemanager.hybridnetwork.HybridNetworkManager serviceManager;

    public VendorSkusImpl(
        VendorSkusClient innerClient, com.azure.resourcemanager.hybridnetwork.HybridNetworkManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public void deleteByResourceGroup(String vendorName, String skuName) {
        this.serviceClient().delete(vendorName, skuName);
    }

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

    public Response<VendorSku> getWithResponse(String vendorName, String skuName, Context context) {
        Response<VendorSkuInner> inner = this.serviceClient().getWithResponse(vendorName, skuName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new VendorSkuImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public VendorSku get(String vendorName, String skuName) {
        VendorSkuInner inner = this.serviceClient().get(vendorName, skuName);
        if (inner != null) {
            return new VendorSkuImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<VendorSku> list(String vendorName) {
        PagedIterable<VendorSkuInner> inner = this.serviceClient().list(vendorName);
        return Utils.mapPage(inner, inner1 -> new VendorSkuImpl(inner1, this.manager()));
    }

    public PagedIterable<VendorSku> list(String vendorName, Context context) {
        PagedIterable<VendorSkuInner> inner = this.serviceClient().list(vendorName, context);
        return Utils.mapPage(inner, inner1 -> new VendorSkuImpl(inner1, this.manager()));
    }

    public VendorSku getById(String id) {
        String vendorName = Utils.getValueFromIdByName(id, "vendors");
        if (vendorName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vendors'.", id)));
        }
        String skuName = Utils.getValueFromIdByName(id, "vendorSkus");
        if (skuName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vendorSkus'.", id)));
        }
        return this.getWithResponse(vendorName, skuName, Context.NONE).getValue();
    }

    public Response<VendorSku> getByIdWithResponse(String id, Context context) {
        String vendorName = Utils.getValueFromIdByName(id, "vendors");
        if (vendorName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vendors'.", id)));
        }
        String skuName = Utils.getValueFromIdByName(id, "vendorSkus");
        if (skuName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vendorSkus'.", id)));
        }
        return this.getWithResponse(vendorName, skuName, context);
    }

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

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

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

    private com.azure.resourcemanager.hybridnetwork.HybridNetworkManager manager() {
        return this.serviceManager;
    }

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