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

package com.azure.resourcemanager.confidentialledger.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.confidentialledger.fluent.models.ManagedCcfInner;
import com.azure.resourcemanager.confidentialledger.models.ManagedCcf;
import com.azure.resourcemanager.confidentialledger.models.ManagedCcfProperties;
import java.util.Collections;
import java.util.Map;

public final class ManagedCcfImpl implements ManagedCcf, ManagedCcf.Definition {
    private ManagedCcfInner innerObject;

    private final com.azure.resourcemanager.confidentialledger.ConfidentialLedgerManager serviceManager;

    ManagedCcfImpl(
        ManagedCcfInner innerObject,
        com.azure.resourcemanager.confidentialledger.ConfidentialLedgerManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = 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 ManagedCcfProperties properties() {
        return this.innerModel().properties();
    }

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

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

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

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

    private com.azure.resourcemanager.confidentialledger.ConfidentialLedgerManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String appName;

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

    public ManagedCcf create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getManagedCcfs()
                .create(resourceGroupName, appName, this.innerModel(), Context.NONE);
        return this;
    }

    public ManagedCcf create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getManagedCcfs()
                .create(resourceGroupName, appName, this.innerModel(), context);
        return this;
    }

    ManagedCcfImpl(String name, com.azure.resourcemanager.confidentialledger.ConfidentialLedgerManager serviceManager) {
        this.innerObject = new ManagedCcfInner();
        this.serviceManager = serviceManager;
        this.appName = name;
    }

    public ManagedCcf refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getManagedCcfs()
                .getByResourceGroupWithResponse(resourceGroupName, appName, Context.NONE)
                .getValue();
        return this;
    }

    public ManagedCcf refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getManagedCcfs()
                .getByResourceGroupWithResponse(resourceGroupName, appName, context)
                .getValue();
        return this;
    }

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

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

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

    public ManagedCcfImpl withProperties(ManagedCcfProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
