// 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.RelationshipResourceFormatInner;
import com.azure.resourcemanager.customerinsights.models.CardinalityTypes;
import com.azure.resourcemanager.customerinsights.models.PropertyDefinition;
import com.azure.resourcemanager.customerinsights.models.ProvisioningStates;
import com.azure.resourcemanager.customerinsights.models.RelationshipResourceFormat;
import com.azure.resourcemanager.customerinsights.models.RelationshipTypeMapping;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class RelationshipResourceFormatImpl
    implements RelationshipResourceFormat, RelationshipResourceFormat.Definition, RelationshipResourceFormat.Update {
    private RelationshipResourceFormatInner 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 CardinalityTypes cardinality() {
        return this.innerModel().cardinality();
    }

    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 OffsetDateTime expiryDateTimeUtc() {
        return this.innerModel().expiryDateTimeUtc();
    }

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

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

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

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String hubName;

    private String relationshipName;

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

    public RelationshipResourceFormat create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRelationships()
                .createOrUpdate(resourceGroupName, hubName, relationshipName, this.innerModel(), Context.NONE);
        return this;
    }

    public RelationshipResourceFormat create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRelationships()
                .createOrUpdate(resourceGroupName, hubName, relationshipName, this.innerModel(), context);
        return this;
    }

    RelationshipResourceFormatImpl(
        String name, com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = new RelationshipResourceFormatInner();
        this.serviceManager = serviceManager;
        this.relationshipName = name;
    }

    public RelationshipResourceFormatImpl update() {
        return this;
    }

    public RelationshipResourceFormat apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRelationships()
                .createOrUpdate(resourceGroupName, hubName, relationshipName, this.innerModel(), Context.NONE);
        return this;
    }

    public RelationshipResourceFormat apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRelationships()
                .createOrUpdate(resourceGroupName, hubName, relationshipName, this.innerModel(), context);
        return this;
    }

    RelationshipResourceFormatImpl(
        RelationshipResourceFormatInner 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.relationshipName = Utils.getValueFromIdByName(innerObject.id(), "relationships");
    }

    public RelationshipResourceFormat refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRelationships()
                .getWithResponse(resourceGroupName, hubName, relationshipName, Context.NONE)
                .getValue();
        return this;
    }

    public RelationshipResourceFormat refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRelationships()
                .getWithResponse(resourceGroupName, hubName, relationshipName, context)
                .getValue();
        return this;
    }

    public RelationshipResourceFormatImpl withCardinality(CardinalityTypes cardinality) {
        this.innerModel().withCardinality(cardinality);
        return this;
    }

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

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

    public RelationshipResourceFormatImpl withExpiryDateTimeUtc(OffsetDateTime expiryDateTimeUtc) {
        this.innerModel().withExpiryDateTimeUtc(expiryDateTimeUtc);
        return this;
    }

    public RelationshipResourceFormatImpl withFields(List<PropertyDefinition> fields) {
        this.innerModel().withFields(fields);
        return this;
    }

    public RelationshipResourceFormatImpl withLookupMappings(List<RelationshipTypeMapping> lookupMappings) {
        this.innerModel().withLookupMappings(lookupMappings);
        return this;
    }

    public RelationshipResourceFormatImpl withProfileType(String profileType) {
        this.innerModel().withProfileType(profileType);
        return this;
    }

    public RelationshipResourceFormatImpl withRelatedProfileType(String relatedProfileType) {
        this.innerModel().withRelatedProfileType(relatedProfileType);
        return this;
    }
}
