// 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.Response;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.deviceupdate.fluent.models.PrivateEndpointConnectionProxyInner;
import com.azure.resourcemanager.deviceupdate.models.PrivateEndpointConnectionProxy;
import com.azure.resourcemanager.deviceupdate.models.PrivateEndpointConnectionProxyProvisioningState;
import com.azure.resourcemanager.deviceupdate.models.PrivateEndpointUpdate;
import com.azure.resourcemanager.deviceupdate.models.RemotePrivateEndpoint;

public final class PrivateEndpointConnectionProxyImpl
    implements PrivateEndpointConnectionProxy,
        PrivateEndpointConnectionProxy.Definition,
        PrivateEndpointConnectionProxy.Update {
    private PrivateEndpointConnectionProxyInner innerObject;

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

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

    public String etag() {
        return this.innerModel().etag();
    }

    public RemotePrivateEndpoint remotePrivateEndpoint() {
        return this.innerModel().remotePrivateEndpoint();
    }

    public String status() {
        return this.innerModel().status();
    }

    public PrivateEndpointConnectionProxyProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public PrivateEndpointConnectionProxyInner innerModel() {
        return this.innerObject;
    }

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

    private String resourceGroupName;

    private String accountName;

    private String privateEndpointConnectionProxyId;

    public PrivateEndpointConnectionProxyImpl withExistingAccount(String resourceGroupName, String accountName) {
        this.resourceGroupName = resourceGroupName;
        this.accountName = accountName;
        return this;
    }

    public PrivateEndpointConnectionProxy create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateEndpointConnectionProxies()
                .createOrUpdate(
                    resourceGroupName, accountName, privateEndpointConnectionProxyId, this.innerModel(), Context.NONE);
        return this;
    }

    public PrivateEndpointConnectionProxy create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateEndpointConnectionProxies()
                .createOrUpdate(
                    resourceGroupName, accountName, privateEndpointConnectionProxyId, this.innerModel(), context);
        return this;
    }

    PrivateEndpointConnectionProxyImpl(
        String name, com.azure.resourcemanager.deviceupdate.DeviceUpdateManager serviceManager) {
        this.innerObject = new PrivateEndpointConnectionProxyInner();
        this.serviceManager = serviceManager;
        this.privateEndpointConnectionProxyId = name;
    }

    public PrivateEndpointConnectionProxyImpl update() {
        return this;
    }

    public PrivateEndpointConnectionProxy apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateEndpointConnectionProxies()
                .createOrUpdate(
                    resourceGroupName, accountName, privateEndpointConnectionProxyId, this.innerModel(), Context.NONE);
        return this;
    }

    public PrivateEndpointConnectionProxy apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateEndpointConnectionProxies()
                .createOrUpdate(
                    resourceGroupName, accountName, privateEndpointConnectionProxyId, this.innerModel(), context);
        return this;
    }

    PrivateEndpointConnectionProxyImpl(
        PrivateEndpointConnectionProxyInner innerObject,
        com.azure.resourcemanager.deviceupdate.DeviceUpdateManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.accountName = Utils.getValueFromIdByName(innerObject.id(), "accounts");
        this.privateEndpointConnectionProxyId =
            Utils.getValueFromIdByName(innerObject.id(), "privateEndpointConnectionProxies");
    }

    public PrivateEndpointConnectionProxy refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateEndpointConnectionProxies()
                .getWithResponse(resourceGroupName, accountName, privateEndpointConnectionProxyId, Context.NONE)
                .getValue();
        return this;
    }

    public PrivateEndpointConnectionProxy refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateEndpointConnectionProxies()
                .getWithResponse(resourceGroupName, accountName, privateEndpointConnectionProxyId, context)
                .getValue();
        return this;
    }

    public void validate(PrivateEndpointConnectionProxyInner privateEndpointConnectionProxy) {
        serviceManager
            .privateEndpointConnectionProxies()
            .validate(resourceGroupName, accountName, privateEndpointConnectionProxyId, privateEndpointConnectionProxy);
    }

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

    public void updatePrivateEndpointProperties(PrivateEndpointUpdate privateEndpointUpdate) {
        serviceManager
            .privateEndpointConnectionProxies()
            .updatePrivateEndpointProperties(
                resourceGroupName, accountName, privateEndpointConnectionProxyId, privateEndpointUpdate);
    }

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

    public PrivateEndpointConnectionProxyImpl withRemotePrivateEndpoint(RemotePrivateEndpoint remotePrivateEndpoint) {
        this.innerModel().withRemotePrivateEndpoint(remotePrivateEndpoint);
        return this;
    }

    public PrivateEndpointConnectionProxyImpl withStatus(String status) {
        this.innerModel().withStatus(status);
        return this;
    }
}
