// 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.ViewResourceFormatInner;
import com.azure.resourcemanager.customerinsights.models.ViewResourceFormat;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.Map;

public final class ViewResourceFormatImpl
    implements ViewResourceFormat, ViewResourceFormat.Definition, ViewResourceFormat.Update {
    private ViewResourceFormatInner 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 viewName() {
        return this.innerModel().viewName();
    }

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

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String hubName;

    private String viewName;

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

    public ViewResourceFormat create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getViews()
                .createOrUpdateWithResponse(resourceGroupName, hubName, viewName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public ViewResourceFormat create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getViews()
                .createOrUpdateWithResponse(resourceGroupName, hubName, viewName, this.innerModel(), context)
                .getValue();
        return this;
    }

    ViewResourceFormatImpl(
        String name, com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = new ViewResourceFormatInner();
        this.serviceManager = serviceManager;
        this.viewName = name;
    }

    public ViewResourceFormatImpl update() {
        return this;
    }

    public ViewResourceFormat apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getViews()
                .createOrUpdateWithResponse(resourceGroupName, hubName, viewName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public ViewResourceFormat apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getViews()
                .createOrUpdateWithResponse(resourceGroupName, hubName, viewName, this.innerModel(), context)
                .getValue();
        return this;
    }

    ViewResourceFormatImpl(
        ViewResourceFormatInner 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.viewName = Utils.getValueFromIdByName(innerObject.id(), "views");
    }

    public ViewResourceFormatImpl withUserId(String userId) {
        this.innerModel().withUserId(userId);
        return this;
    }

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

    public ViewResourceFormatImpl withDefinition(String definition) {
        this.innerModel().withDefinition(definition);
        return this;
    }
}
