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

package com.azure.resourcemanager.servicefabric.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.servicefabric.fluent.models.ApplicationTypeVersionResourceInner;
import com.azure.resourcemanager.servicefabric.models.ApplicationTypeVersionResource;
import java.util.Collections;
import java.util.Map;

public final class ApplicationTypeVersionResourceImpl
    implements ApplicationTypeVersionResource,
        ApplicationTypeVersionResource.Definition,
        ApplicationTypeVersionResource.Update {
    private ApplicationTypeVersionResourceInner innerObject;

    private final com.azure.resourcemanager.servicefabric.ServiceFabricManager 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 String etag() {
        return this.innerModel().etag();
    }

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

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.servicefabric.ServiceFabricManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String clusterName;

    private String applicationTypeName;

    private String version;

    public ApplicationTypeVersionResourceImpl withExistingApplicationType(
        String resourceGroupName, String clusterName, String applicationTypeName) {
        this.resourceGroupName = resourceGroupName;
        this.clusterName = clusterName;
        this.applicationTypeName = applicationTypeName;
        return this;
    }

    public ApplicationTypeVersionResource create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getApplicationTypeVersions()
                .createOrUpdate(
                    resourceGroupName, clusterName, applicationTypeName, version, this.innerModel(), Context.NONE);
        return this;
    }

    public ApplicationTypeVersionResource create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getApplicationTypeVersions()
                .createOrUpdate(
                    resourceGroupName, clusterName, applicationTypeName, version, this.innerModel(), context);
        return this;
    }

    ApplicationTypeVersionResourceImpl(
        String name, com.azure.resourcemanager.servicefabric.ServiceFabricManager serviceManager) {
        this.innerObject = new ApplicationTypeVersionResourceInner();
        this.serviceManager = serviceManager;
        this.version = name;
    }

    public ApplicationTypeVersionResourceImpl update() {
        return this;
    }

    public ApplicationTypeVersionResource apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getApplicationTypeVersions()
                .createOrUpdate(
                    resourceGroupName, clusterName, applicationTypeName, version, this.innerModel(), Context.NONE);
        return this;
    }

    public ApplicationTypeVersionResource apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getApplicationTypeVersions()
                .createOrUpdate(
                    resourceGroupName, clusterName, applicationTypeName, version, this.innerModel(), context);
        return this;
    }

    ApplicationTypeVersionResourceImpl(
        ApplicationTypeVersionResourceInner innerObject,
        com.azure.resourcemanager.servicefabric.ServiceFabricManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.clusterName = Utils.getValueFromIdByName(innerObject.id(), "clusters");
        this.applicationTypeName = Utils.getValueFromIdByName(innerObject.id(), "applicationTypes");
        this.version = Utils.getValueFromIdByName(innerObject.id(), "versions");
    }

    public ApplicationTypeVersionResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getApplicationTypeVersions()
                .getWithResponse(resourceGroupName, clusterName, applicationTypeName, version, Context.NONE)
                .getValue();
        return this;
    }

    public ApplicationTypeVersionResource refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getApplicationTypeVersions()
                .getWithResponse(resourceGroupName, clusterName, applicationTypeName, version, context)
                .getValue();
        return this;
    }

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

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

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

    public ApplicationTypeVersionResourceImpl withAppPackageUrl(String appPackageUrl) {
        this.innerModel().withAppPackageUrl(appPackageUrl);
        return this;
    }
}
