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

package com.azure.resourcemanager.mixedreality.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.mixedreality.fluent.models.SpatialAnchorsAccountInner;
import com.azure.resourcemanager.mixedreality.models.AccountKeyRegenerateRequest;
import com.azure.resourcemanager.mixedreality.models.AccountKeys;
import com.azure.resourcemanager.mixedreality.models.Identity;
import com.azure.resourcemanager.mixedreality.models.Sku;
import com.azure.resourcemanager.mixedreality.models.SpatialAnchorsAccount;
import java.util.Collections;
import java.util.Map;

public final class SpatialAnchorsAccountImpl
    implements SpatialAnchorsAccount, SpatialAnchorsAccount.Definition, SpatialAnchorsAccount.Update {
    private SpatialAnchorsAccountInner innerObject;

    private final com.azure.resourcemanager.mixedreality.MixedRealityManager serviceManager;

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

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

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

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

    public Map<String, String> tags() {
        Map<String, String> inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public Identity identity() {
        return this.innerModel().identity();
    }

    public Identity plan() {
        return this.innerModel().plan();
    }

    public Sku sku() {
        return this.innerModel().sku();
    }

    public Sku kind() {
        return this.innerModel().kind();
    }

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

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

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

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

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.mixedreality.MixedRealityManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String accountName;

    public SpatialAnchorsAccountImpl withExistingResourceGroup(String resourceGroupName) {
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public SpatialAnchorsAccount create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSpatialAnchorsAccounts()
                .createWithResponse(resourceGroupName, accountName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public SpatialAnchorsAccount create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSpatialAnchorsAccounts()
                .createWithResponse(resourceGroupName, accountName, this.innerModel(), context)
                .getValue();
        return this;
    }

    SpatialAnchorsAccountImpl(String name, com.azure.resourcemanager.mixedreality.MixedRealityManager serviceManager) {
        this.innerObject = new SpatialAnchorsAccountInner();
        this.serviceManager = serviceManager;
        this.accountName = name;
    }

    public SpatialAnchorsAccountImpl update() {
        return this;
    }

    public SpatialAnchorsAccount apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSpatialAnchorsAccounts()
                .updateWithResponse(resourceGroupName, accountName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public SpatialAnchorsAccount apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSpatialAnchorsAccounts()
                .updateWithResponse(resourceGroupName, accountName, this.innerModel(), context)
                .getValue();
        return this;
    }

    SpatialAnchorsAccountImpl(
        SpatialAnchorsAccountInner innerObject,
        com.azure.resourcemanager.mixedreality.MixedRealityManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.accountName = Utils.getValueFromIdByName(innerObject.id(), "spatialAnchorsAccounts");
    }

    public SpatialAnchorsAccount refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSpatialAnchorsAccounts()
                .getByResourceGroupWithResponse(resourceGroupName, accountName, Context.NONE)
                .getValue();
        return this;
    }

    public SpatialAnchorsAccount refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSpatialAnchorsAccounts()
                .getByResourceGroupWithResponse(resourceGroupName, accountName, context)
                .getValue();
        return this;
    }

    public Response<AccountKeys> listKeysWithResponse(Context context) {
        return serviceManager.spatialAnchorsAccounts().listKeysWithResponse(resourceGroupName, accountName, context);
    }

    public AccountKeys listKeys() {
        return serviceManager.spatialAnchorsAccounts().listKeys(resourceGroupName, accountName);
    }

    public Response<AccountKeys> regenerateKeysWithResponse(AccountKeyRegenerateRequest regenerate, Context context) {
        return serviceManager
            .spatialAnchorsAccounts()
            .regenerateKeysWithResponse(resourceGroupName, accountName, regenerate, context);
    }

    public AccountKeys regenerateKeys(AccountKeyRegenerateRequest regenerate) {
        return serviceManager.spatialAnchorsAccounts().regenerateKeys(resourceGroupName, accountName, regenerate);
    }

    public SpatialAnchorsAccountImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

    public SpatialAnchorsAccountImpl withRegion(String location) {
        this.innerModel().withLocation(location);
        return this;
    }

    public SpatialAnchorsAccountImpl withTags(Map<String, String> tags) {
        this.innerModel().withTags(tags);
        return this;
    }

    public SpatialAnchorsAccountImpl withIdentity(Identity identity) {
        this.innerModel().withIdentity(identity);
        return this;
    }

    public SpatialAnchorsAccountImpl withPlan(Identity plan) {
        this.innerModel().withPlan(plan);
        return this;
    }

    public SpatialAnchorsAccountImpl withSku(Sku sku) {
        this.innerModel().withSku(sku);
        return this;
    }

    public SpatialAnchorsAccountImpl withKind(Sku kind) {
        this.innerModel().withKind(kind);
        return this;
    }

    public SpatialAnchorsAccountImpl withStorageAccountName(String storageAccountName) {
        this.innerModel().withStorageAccountName(storageAccountName);
        return this;
    }
}
