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

package com.azure.resourcemanager.avs.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.avs.fluent.models.WorkloadNetworkDhcpInner;
import com.azure.resourcemanager.avs.models.WorkloadNetworkDhcp;
import com.azure.resourcemanager.avs.models.WorkloadNetworkDhcpEntity;

public final class WorkloadNetworkDhcpImpl
    implements WorkloadNetworkDhcp, WorkloadNetworkDhcp.Definition, WorkloadNetworkDhcp.Update {
    private WorkloadNetworkDhcpInner innerObject;

    private final com.azure.resourcemanager.avs.AvsManager serviceManager;

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

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

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

    public WorkloadNetworkDhcpEntity properties() {
        return this.innerModel().properties();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.avs.AvsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String privateCloudName;

    private String dhcpId;

    public WorkloadNetworkDhcpImpl withExistingPrivateCloud(String resourceGroupName, String privateCloudName) {
        this.resourceGroupName = resourceGroupName;
        this.privateCloudName = privateCloudName;
        return this;
    }

    public WorkloadNetworkDhcp create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .createDhcp(resourceGroupName, privateCloudName, dhcpId, this.innerModel(), Context.NONE);
        return this;
    }

    public WorkloadNetworkDhcp create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .createDhcp(resourceGroupName, privateCloudName, dhcpId, this.innerModel(), context);
        return this;
    }

    WorkloadNetworkDhcpImpl(String name, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = new WorkloadNetworkDhcpInner();
        this.serviceManager = serviceManager;
        this.dhcpId = name;
    }

    public WorkloadNetworkDhcpImpl update() {
        return this;
    }

    public WorkloadNetworkDhcp apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .updateDhcp(resourceGroupName, privateCloudName, dhcpId, this.innerModel(), Context.NONE);
        return this;
    }

    public WorkloadNetworkDhcp apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .updateDhcp(resourceGroupName, privateCloudName, dhcpId, this.innerModel(), context);
        return this;
    }

    WorkloadNetworkDhcpImpl(
        WorkloadNetworkDhcpInner innerObject, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.privateCloudName = Utils.getValueFromIdByName(innerObject.id(), "privateClouds");
        this.dhcpId = Utils.getValueFromIdByName(innerObject.id(), "dhcpConfigurations");
    }

    public WorkloadNetworkDhcp refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .getDhcpWithResponse(resourceGroupName, dhcpId, privateCloudName, Context.NONE)
                .getValue();
        return this;
    }

    public WorkloadNetworkDhcp refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .getDhcpWithResponse(resourceGroupName, dhcpId, privateCloudName, context)
                .getValue();
        return this;
    }

    public WorkloadNetworkDhcpImpl withProperties(WorkloadNetworkDhcpEntity properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
