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

package com.azure.resourcemanager.logic.implementation;

import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.logic.fluent.models.BatchConfigurationInner;
import com.azure.resourcemanager.logic.models.BatchConfiguration;
import com.azure.resourcemanager.logic.models.BatchConfigurationProperties;
import java.util.Collections;
import java.util.Map;

public final class BatchConfigurationImpl
    implements BatchConfiguration, BatchConfiguration.Definition, BatchConfiguration.Update {
    private BatchConfigurationInner innerObject;

    private final com.azure.resourcemanager.logic.LogicManager 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 BatchConfigurationProperties properties() {
        return this.innerModel().properties();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.logic.LogicManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String integrationAccountName;

    private String batchConfigurationName;

    public BatchConfigurationImpl withExistingIntegrationAccount(
        String resourceGroupName, String integrationAccountName) {
        this.resourceGroupName = resourceGroupName;
        this.integrationAccountName = integrationAccountName;
        return this;
    }

    public BatchConfiguration create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountBatchConfigurations()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, batchConfigurationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public BatchConfiguration create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountBatchConfigurations()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, batchConfigurationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    BatchConfigurationImpl(String name, com.azure.resourcemanager.logic.LogicManager serviceManager) {
        this.innerObject = new BatchConfigurationInner();
        this.serviceManager = serviceManager;
        this.batchConfigurationName = name;
    }

    public BatchConfigurationImpl update() {
        return this;
    }

    public BatchConfiguration apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountBatchConfigurations()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, batchConfigurationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public BatchConfiguration apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountBatchConfigurations()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, batchConfigurationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    BatchConfigurationImpl(
        BatchConfigurationInner innerObject, com.azure.resourcemanager.logic.LogicManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.integrationAccountName = Utils.getValueFromIdByName(innerObject.id(), "integrationAccounts");
        this.batchConfigurationName = Utils.getValueFromIdByName(innerObject.id(), "batchConfigurations");
    }

    public BatchConfiguration refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountBatchConfigurations()
                .getWithResponse(resourceGroupName, integrationAccountName, batchConfigurationName, Context.NONE)
                .getValue();
        return this;
    }

    public BatchConfiguration refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountBatchConfigurations()
                .getWithResponse(resourceGroupName, integrationAccountName, batchConfigurationName, context)
                .getValue();
        return this;
    }

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

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

    public BatchConfigurationImpl withProperties(BatchConfigurationProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }

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