// 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.IntegrationAccountSessionInner;
import com.azure.resourcemanager.logic.models.IntegrationAccountSession;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.Map;

public final class IntegrationAccountSessionImpl
    implements IntegrationAccountSession, IntegrationAccountSession.Definition, IntegrationAccountSession.Update {
    private IntegrationAccountSessionInner 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 OffsetDateTime createdTime() {
        return this.innerModel().createdTime();
    }

    public OffsetDateTime changedTime() {
        return this.innerModel().changedTime();
    }

    public Object content() {
        return this.innerModel().content();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String integrationAccountName;

    private String sessionName;

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

    public IntegrationAccountSession create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountSessions()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, sessionName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public IntegrationAccountSession create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountSessions()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, sessionName, this.innerModel(), context)
                .getValue();
        return this;
    }

    IntegrationAccountSessionImpl(String name, com.azure.resourcemanager.logic.LogicManager serviceManager) {
        this.innerObject = new IntegrationAccountSessionInner();
        this.serviceManager = serviceManager;
        this.sessionName = name;
    }

    public IntegrationAccountSessionImpl update() {
        return this;
    }

    public IntegrationAccountSession apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountSessions()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, sessionName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public IntegrationAccountSession apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountSessions()
                .createOrUpdateWithResponse(
                    resourceGroupName, integrationAccountName, sessionName, this.innerModel(), context)
                .getValue();
        return this;
    }

    IntegrationAccountSessionImpl(
        IntegrationAccountSessionInner 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.sessionName = Utils.getValueFromIdByName(innerObject.id(), "sessions");
    }

    public IntegrationAccountSession refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountSessions()
                .getWithResponse(resourceGroupName, integrationAccountName, sessionName, Context.NONE)
                .getValue();
        return this;
    }

    public IntegrationAccountSession refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIntegrationAccountSessions()
                .getWithResponse(resourceGroupName, integrationAccountName, sessionName, context)
                .getValue();
        return this;
    }

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

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

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

    public IntegrationAccountSessionImpl withContent(Object content) {
        this.innerModel().withContent(content);
        return this;
    }
}
