// 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.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.resourcemanager.customerinsights.fluent.models.ProfileResourceFormatInner;
import com.azure.resourcemanager.customerinsights.models.EntityTypes;
import com.azure.resourcemanager.customerinsights.models.KpiDefinition;
import com.azure.resourcemanager.customerinsights.models.ProfileResourceFormat;
import com.azure.resourcemanager.customerinsights.models.PropertyDefinition;
import com.azure.resourcemanager.customerinsights.models.ProvisioningStates;
import com.azure.resourcemanager.customerinsights.models.StrongId;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class ProfileResourceFormatImpl
    implements ProfileResourceFormat, ProfileResourceFormat.Definition, ProfileResourceFormat.Update {
    private ProfileResourceFormatInner 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 List<StrongId> strongIds() {
        List<StrongId> inner = this.innerModel().strongIds();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

    public EntityTypes entityType() {
        return this.innerModel().entityType();
    }

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

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

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

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

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

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

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

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

    public Map<String, List<String>> attributes() {
        Map<String, List<String>> inner = this.innerModel().attributes();
        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 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, Map<String, String>> localizedAttributes() {
        Map<String, Map<String, String>> inner = this.innerModel().localizedAttributes();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String hubName;

    private String profileName;

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

    public ProfileResourceFormat create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getProfiles()
                .createOrUpdate(resourceGroupName, hubName, profileName, this.innerModel(), Context.NONE);
        return this;
    }

    public ProfileResourceFormat create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getProfiles()
                .createOrUpdate(resourceGroupName, hubName, profileName, this.innerModel(), context);
        return this;
    }

    ProfileResourceFormatImpl(
        String name, com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = new ProfileResourceFormatInner();
        this.serviceManager = serviceManager;
        this.profileName = name;
    }

    public ProfileResourceFormatImpl update() {
        return this;
    }

    public ProfileResourceFormat apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getProfiles()
                .createOrUpdate(resourceGroupName, hubName, profileName, this.innerModel(), Context.NONE);
        return this;
    }

    public ProfileResourceFormat apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getProfiles()
                .createOrUpdate(resourceGroupName, hubName, profileName, this.innerModel(), context);
        return this;
    }

    ProfileResourceFormatImpl(
        ProfileResourceFormatInner 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.profileName = Utils.getValueFromIdByName(innerObject.id(), "profiles");
    }

    public ProfileResourceFormat refresh() {
        String localLocaleCode = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getProfiles()
                .getWithResponse(resourceGroupName, hubName, profileName, localLocaleCode, Context.NONE)
                .getValue();
        return this;
    }

    public ProfileResourceFormat refresh(Context context) {
        String localLocaleCode = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getProfiles()
                .getWithResponse(resourceGroupName, hubName, profileName, localLocaleCode, context)
                .getValue();
        return this;
    }

    public Response<List<KpiDefinition>> getEnrichingKpisWithResponse(Context context) {
        return serviceManager.profiles().getEnrichingKpisWithResponse(resourceGroupName, hubName, profileName, context);
    }

    public List<KpiDefinition> getEnrichingKpis() {
        return serviceManager.profiles().getEnrichingKpis(resourceGroupName, hubName, profileName);
    }

    public ProfileResourceFormatImpl withStrongIds(List<StrongId> strongIds) {
        this.innerModel().withStrongIds(strongIds);
        return this;
    }

    public ProfileResourceFormatImpl withApiEntitySetName(String apiEntitySetName) {
        this.innerModel().withApiEntitySetName(apiEntitySetName);
        return this;
    }

    public ProfileResourceFormatImpl withEntityType(EntityTypes entityType) {
        this.innerModel().withEntityType(entityType);
        return this;
    }

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

    public ProfileResourceFormatImpl withInstancesCount(Integer instancesCount) {
        this.innerModel().withInstancesCount(instancesCount);
        return this;
    }

    public ProfileResourceFormatImpl withSchemaItemTypeLink(String schemaItemTypeLink) {
        this.innerModel().withSchemaItemTypeLink(schemaItemTypeLink);
        return this;
    }

    public ProfileResourceFormatImpl withTimestampFieldName(String timestampFieldName) {
        this.innerModel().withTimestampFieldName(timestampFieldName);
        return this;
    }

    public ProfileResourceFormatImpl withTypeName(String typeName) {
        this.innerModel().withTypeName(typeName);
        return this;
    }

    public ProfileResourceFormatImpl withAttributes(Map<String, List<String>> attributes) {
        this.innerModel().withAttributes(attributes);
        return this;
    }

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

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

    public ProfileResourceFormatImpl withLocalizedAttributes(Map<String, Map<String, String>> localizedAttributes) {
        this.innerModel().withLocalizedAttributes(localizedAttributes);
        return this;
    }

    public ProfileResourceFormatImpl withSmallImage(String smallImage) {
        this.innerModel().withSmallImage(smallImage);
        return this;
    }

    public ProfileResourceFormatImpl withMediumImage(String mediumImage) {
        this.innerModel().withMediumImage(mediumImage);
        return this;
    }

    public ProfileResourceFormatImpl withLargeImage(String largeImage) {
        this.innerModel().withLargeImage(largeImage);
        return this;
    }
}
