// 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.HcxEnterpriseSiteInner;
import com.azure.resourcemanager.avs.models.HcxEnterpriseSite;
import com.azure.resourcemanager.avs.models.HcxEnterpriseSiteStatus;

public final class HcxEnterpriseSiteImpl
    implements HcxEnterpriseSite, HcxEnterpriseSite.Definition, HcxEnterpriseSite.Update {
    private HcxEnterpriseSiteInner 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 String activationKey() {
        return this.innerModel().activationKey();
    }

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String privateCloudName;

    private String hcxEnterpriseSiteName;

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

    public HcxEnterpriseSite create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHcxEnterpriseSites()
                .createOrUpdateWithResponse(
                    resourceGroupName, privateCloudName, hcxEnterpriseSiteName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public HcxEnterpriseSite create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHcxEnterpriseSites()
                .createOrUpdateWithResponse(
                    resourceGroupName, privateCloudName, hcxEnterpriseSiteName, this.innerModel(), context)
                .getValue();
        return this;
    }

    HcxEnterpriseSiteImpl(String name, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = new HcxEnterpriseSiteInner();
        this.serviceManager = serviceManager;
        this.hcxEnterpriseSiteName = name;
    }

    public HcxEnterpriseSiteImpl update() {
        return this;
    }

    public HcxEnterpriseSite apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHcxEnterpriseSites()
                .createOrUpdateWithResponse(
                    resourceGroupName, privateCloudName, hcxEnterpriseSiteName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public HcxEnterpriseSite apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHcxEnterpriseSites()
                .createOrUpdateWithResponse(
                    resourceGroupName, privateCloudName, hcxEnterpriseSiteName, this.innerModel(), context)
                .getValue();
        return this;
    }

    HcxEnterpriseSiteImpl(HcxEnterpriseSiteInner 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.hcxEnterpriseSiteName = Utils.getValueFromIdByName(innerObject.id(), "hcxEnterpriseSites");
    }

    public HcxEnterpriseSite refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHcxEnterpriseSites()
                .getWithResponse(resourceGroupName, privateCloudName, hcxEnterpriseSiteName, Context.NONE)
                .getValue();
        return this;
    }

    public HcxEnterpriseSite refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHcxEnterpriseSites()
                .getWithResponse(resourceGroupName, privateCloudName, hcxEnterpriseSiteName, context)
                .getValue();
        return this;
    }
}
