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

package com.azure.resourcemanager.customerinsights.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.customerinsights.fluent.models.ConnectorResourceFormatInner;
import com.azure.resourcemanager.customerinsights.models.ConnectorResourceFormat;
import com.azure.resourcemanager.customerinsights.models.ConnectorStates;
import com.azure.resourcemanager.customerinsights.models.ConnectorTypes;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.Map;

public final class ConnectorResourceFormatImpl
    implements ConnectorResourceFormat, ConnectorResourceFormat.Definition, ConnectorResourceFormat.Update {
    private ConnectorResourceFormatInner innerObject;

    private final com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager;

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

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

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

    public Integer connectorId() {
        return this.innerModel().connectorId();
    }

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

    public ConnectorTypes connectorType() {
        return this.innerModel().connectorType();
    }

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

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

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

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

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

    public ConnectorStates state() {
        return this.innerModel().state();
    }

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

    public Boolean isInternal() {
        return this.innerModel().isInternal();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.customerinsights.CustomerInsightsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String hubName;

    private String connectorName;

    public ConnectorResourceFormatImpl withExistingHub(String resourceGroupName, String hubName) {
        this.resourceGroupName = resourceGroupName;
        this.hubName = hubName;
        return this;
    }

    public ConnectorResourceFormat create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdate(resourceGroupName, hubName, connectorName, this.innerModel(), Context.NONE);
        return this;
    }

    public ConnectorResourceFormat create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdate(resourceGroupName, hubName, connectorName, this.innerModel(), context);
        return this;
    }

    ConnectorResourceFormatImpl(
        String name, com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = new ConnectorResourceFormatInner();
        this.serviceManager = serviceManager;
        this.connectorName = name;
    }

    public ConnectorResourceFormatImpl update() {
        return this;
    }

    public ConnectorResourceFormat apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdate(resourceGroupName, hubName, connectorName, this.innerModel(), Context.NONE);
        return this;
    }

    public ConnectorResourceFormat apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdate(resourceGroupName, hubName, connectorName, this.innerModel(), context);
        return this;
    }

    ConnectorResourceFormatImpl(
        ConnectorResourceFormatInner innerObject,
        com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.hubName = Utils.getValueFromIdByName(innerObject.id(), "hubs");
        this.connectorName = Utils.getValueFromIdByName(innerObject.id(), "connectors");
    }

    public ConnectorResourceFormat refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .getWithResponse(resourceGroupName, hubName, connectorName, Context.NONE)
                .getValue();
        return this;
    }

    public ConnectorResourceFormat refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .getWithResponse(resourceGroupName, hubName, connectorName, context)
                .getValue();
        return this;
    }

    public ConnectorResourceFormatImpl withConnectorName(String connectorName) {
        this.innerModel().withConnectorName(connectorName);
        return this;
    }

    public ConnectorResourceFormatImpl withConnectorType(ConnectorTypes connectorType) {
        this.innerModel().withConnectorType(connectorType);
        return this;
    }

    public ConnectorResourceFormatImpl withDisplayName(String displayName) {
        this.innerModel().withDisplayName(displayName);
        return this;
    }

    public ConnectorResourceFormatImpl withDescription(String description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public ConnectorResourceFormatImpl withConnectorProperties(Map<String, Object> connectorProperties) {
        this.innerModel().withConnectorProperties(connectorProperties);
        return this;
    }

    public ConnectorResourceFormatImpl withIsInternal(Boolean isInternal) {
        this.innerModel().withIsInternal(isInternal);
        return this;
    }
}
