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

package com.azure.resourcemanager.deviceupdate.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.deviceupdate.fluent.PrivateEndpointConnectionProxiesClient;
import com.azure.resourcemanager.deviceupdate.fluent.models.PrivateEndpointConnectionProxyInner;
import com.azure.resourcemanager.deviceupdate.models.PrivateEndpointConnectionProxies;
import com.azure.resourcemanager.deviceupdate.models.PrivateEndpointConnectionProxy;
import com.azure.resourcemanager.deviceupdate.models.PrivateEndpointUpdate;

public final class PrivateEndpointConnectionProxiesImpl implements PrivateEndpointConnectionProxies {
    private static final ClientLogger LOGGER = new ClientLogger(PrivateEndpointConnectionProxiesImpl.class);

    private final PrivateEndpointConnectionProxiesClient innerClient;

    private final com.azure.resourcemanager.deviceupdate.DeviceUpdateManager serviceManager;

    public PrivateEndpointConnectionProxiesImpl(
        PrivateEndpointConnectionProxiesClient innerClient,
        com.azure.resourcemanager.deviceupdate.DeviceUpdateManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<PrivateEndpointConnectionProxy> listByAccount(String resourceGroupName, String accountName) {
        PagedIterable<PrivateEndpointConnectionProxyInner> inner =
            this.serviceClient().listByAccount(resourceGroupName, accountName);
        return Utils.mapPage(inner, inner1 -> new PrivateEndpointConnectionProxyImpl(inner1, this.manager()));
    }

    public PagedIterable<PrivateEndpointConnectionProxy> listByAccount(
        String resourceGroupName, String accountName, Context context) {
        PagedIterable<PrivateEndpointConnectionProxyInner> inner =
            this.serviceClient().listByAccount(resourceGroupName, accountName, context);
        return Utils.mapPage(inner, inner1 -> new PrivateEndpointConnectionProxyImpl(inner1, this.manager()));
    }

    public void validate(
        String resourceGroupName,
        String accountName,
        String privateEndpointConnectionProxyId,
        PrivateEndpointConnectionProxyInner privateEndpointConnectionProxy) {
        this
            .serviceClient()
            .validate(resourceGroupName, accountName, privateEndpointConnectionProxyId, privateEndpointConnectionProxy);
    }

    public Response<Void> validateWithResponse(
        String resourceGroupName,
        String accountName,
        String privateEndpointConnectionProxyId,
        PrivateEndpointConnectionProxyInner privateEndpointConnectionProxy,
        Context context) {
        return this
            .serviceClient()
            .validateWithResponse(
                resourceGroupName,
                accountName,
                privateEndpointConnectionProxyId,
                privateEndpointConnectionProxy,
                context);
    }

    public void updatePrivateEndpointProperties(
        String resourceGroupName,
        String accountName,
        String privateEndpointConnectionProxyId,
        PrivateEndpointUpdate privateEndpointUpdate) {
        this
            .serviceClient()
            .updatePrivateEndpointProperties(
                resourceGroupName, accountName, privateEndpointConnectionProxyId, privateEndpointUpdate);
    }

    public Response<Void> updatePrivateEndpointPropertiesWithResponse(
        String resourceGroupName,
        String accountName,
        String privateEndpointConnectionProxyId,
        PrivateEndpointUpdate privateEndpointUpdate,
        Context context) {
        return this
            .serviceClient()
            .updatePrivateEndpointPropertiesWithResponse(
                resourceGroupName, accountName, privateEndpointConnectionProxyId, privateEndpointUpdate, context);
    }

    public PrivateEndpointConnectionProxy get(
        String resourceGroupName, String accountName, String privateEndpointConnectionProxyId) {
        PrivateEndpointConnectionProxyInner inner =
            this.serviceClient().get(resourceGroupName, accountName, privateEndpointConnectionProxyId);
        if (inner != null) {
            return new PrivateEndpointConnectionProxyImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<PrivateEndpointConnectionProxy> getWithResponse(
        String resourceGroupName, String accountName, String privateEndpointConnectionProxyId, Context context) {
        Response<PrivateEndpointConnectionProxyInner> inner =
            this
                .serviceClient()
                .getWithResponse(resourceGroupName, accountName, privateEndpointConnectionProxyId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new PrivateEndpointConnectionProxyImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public void delete(String resourceGroupName, String accountName, String privateEndpointConnectionProxyId) {
        this.serviceClient().delete(resourceGroupName, accountName, privateEndpointConnectionProxyId);
    }

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

    public PrivateEndpointConnectionProxy 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 accountName = Utils.getValueFromIdByName(id, "accounts");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'accounts'.", id)));
        }
        String privateEndpointConnectionProxyId = Utils.getValueFromIdByName(id, "privateEndpointConnectionProxies");
        if (privateEndpointConnectionProxyId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'privateEndpointConnectionProxies'.",
                                id)));
        }
        return this
            .getWithResponse(resourceGroupName, accountName, privateEndpointConnectionProxyId, Context.NONE)
            .getValue();
    }

    public Response<PrivateEndpointConnectionProxy> 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 accountName = Utils.getValueFromIdByName(id, "accounts");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'accounts'.", id)));
        }
        String privateEndpointConnectionProxyId = Utils.getValueFromIdByName(id, "privateEndpointConnectionProxies");
        if (privateEndpointConnectionProxyId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'privateEndpointConnectionProxies'.",
                                id)));
        }
        return this.getWithResponse(resourceGroupName, accountName, privateEndpointConnectionProxyId, 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 accountName = Utils.getValueFromIdByName(id, "accounts");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'accounts'.", id)));
        }
        String privateEndpointConnectionProxyId = Utils.getValueFromIdByName(id, "privateEndpointConnectionProxies");
        if (privateEndpointConnectionProxyId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'privateEndpointConnectionProxies'.",
                                id)));
        }
        this.delete(resourceGroupName, accountName, privateEndpointConnectionProxyId, 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 accountName = Utils.getValueFromIdByName(id, "accounts");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'accounts'.", id)));
        }
        String privateEndpointConnectionProxyId = Utils.getValueFromIdByName(id, "privateEndpointConnectionProxies");
        if (privateEndpointConnectionProxyId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'privateEndpointConnectionProxies'.",
                                id)));
        }
        this.delete(resourceGroupName, accountName, privateEndpointConnectionProxyId, context);
    }

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

    private com.azure.resourcemanager.deviceupdate.DeviceUpdateManager manager() {
        return this.serviceManager;
    }

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