// 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.VendorsClient;
import com.azure.resourcemanager.hybridnetwork.fluent.models.VendorInner;
import com.azure.resourcemanager.hybridnetwork.models.Vendor;
import com.azure.resourcemanager.hybridnetwork.models.Vendors;

public final class VendorsImpl implements Vendors {
    private static final ClientLogger LOGGER = new ClientLogger(VendorsImpl.class);

    private final VendorsClient innerClient;

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

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

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

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

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

    public Vendor get(String vendorName) {
        VendorInner inner = this.serviceClient().get(vendorName);
        if (inner != null) {
            return new VendorImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<Vendor> list() {
        PagedIterable<VendorInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new VendorImpl(inner1, this.manager()));
    }

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

    public Vendor 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)));
        }
        return this.getWithResponse(vendorName, Context.NONE).getValue();
    }

    public Response<Vendor> 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)));
        }
        return this.getWithResponse(vendorName, 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)));
        }
        this.delete(vendorName, 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)));
        }
        this.delete(vendorName, context);
    }

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

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

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