// 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.LinkResourceFormatInner;
import com.azure.resourcemanager.customerinsights.models.EntityType;
import com.azure.resourcemanager.customerinsights.models.InstanceOperationType;
import com.azure.resourcemanager.customerinsights.models.LinkResourceFormat;
import com.azure.resourcemanager.customerinsights.models.ParticipantPropertyReference;
import com.azure.resourcemanager.customerinsights.models.ProvisioningStates;
import com.azure.resourcemanager.customerinsights.models.TypePropertiesMapping;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class LinkResourceFormatImpl
    implements LinkResourceFormat, LinkResourceFormat.Definition, LinkResourceFormat.Update {
    private LinkResourceFormatInner 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 String tenantId() {
        return this.innerModel().tenantId();
    }

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

    public EntityType sourceEntityType() {
        return this.innerModel().sourceEntityType();
    }

    public EntityType targetEntityType() {
        return this.innerModel().targetEntityType();
    }

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

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

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

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

    public List<TypePropertiesMapping> mappings() {
        List<TypePropertiesMapping> inner = this.innerModel().mappings();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<ParticipantPropertyReference> participantPropertyReferences() {
        List<ParticipantPropertyReference> inner = this.innerModel().participantPropertyReferences();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

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

    public InstanceOperationType operationType() {
        return this.innerModel().operationType();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String hubName;

    private String linkName;

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

    public LinkResourceFormat create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLinks()
                .createOrUpdate(resourceGroupName, hubName, linkName, this.innerModel(), Context.NONE);
        return this;
    }

    public LinkResourceFormat create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLinks()
                .createOrUpdate(resourceGroupName, hubName, linkName, this.innerModel(), context);
        return this;
    }

    LinkResourceFormatImpl(
        String name, com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = new LinkResourceFormatInner();
        this.serviceManager = serviceManager;
        this.linkName = name;
    }

    public LinkResourceFormatImpl update() {
        return this;
    }

    public LinkResourceFormat apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLinks()
                .createOrUpdate(resourceGroupName, hubName, linkName, this.innerModel(), Context.NONE);
        return this;
    }

    public LinkResourceFormat apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLinks()
                .createOrUpdate(resourceGroupName, hubName, linkName, this.innerModel(), context);
        return this;
    }

    LinkResourceFormatImpl(
        LinkResourceFormatInner 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.linkName = Utils.getValueFromIdByName(innerObject.id(), "links");
    }

    public LinkResourceFormat refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLinks()
                .getWithResponse(resourceGroupName, hubName, linkName, Context.NONE)
                .getValue();
        return this;
    }

    public LinkResourceFormat refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getLinks()
                .getWithResponse(resourceGroupName, hubName, linkName, context)
                .getValue();
        return this;
    }

    public LinkResourceFormatImpl withSourceEntityType(EntityType sourceEntityType) {
        this.innerModel().withSourceEntityType(sourceEntityType);
        return this;
    }

    public LinkResourceFormatImpl withTargetEntityType(EntityType targetEntityType) {
        this.innerModel().withTargetEntityType(targetEntityType);
        return this;
    }

    public LinkResourceFormatImpl withSourceEntityTypeName(String sourceEntityTypeName) {
        this.innerModel().withSourceEntityTypeName(sourceEntityTypeName);
        return this;
    }

    public LinkResourceFormatImpl withTargetEntityTypeName(String targetEntityTypeName) {
        this.innerModel().withTargetEntityTypeName(targetEntityTypeName);
        return this;
    }

    public LinkResourceFormatImpl withDisplayName(Map<String, String> displayName) {
        this.innerModel().withDisplayName(displayName);
        return this;
    }

    public LinkResourceFormatImpl withDescription(Map<String, String> description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public LinkResourceFormatImpl withMappings(List<TypePropertiesMapping> mappings) {
        this.innerModel().withMappings(mappings);
        return this;
    }

    public LinkResourceFormatImpl withParticipantPropertyReferences(
        List<ParticipantPropertyReference> participantPropertyReferences) {
        this.innerModel().withParticipantPropertyReferences(participantPropertyReferences);
        return this;
    }

    public LinkResourceFormatImpl withReferenceOnly(Boolean referenceOnly) {
        this.innerModel().withReferenceOnly(referenceOnly);
        return this;
    }

    public LinkResourceFormatImpl withOperationType(InstanceOperationType operationType) {
        this.innerModel().withOperationType(operationType);
        return this;
    }
}
