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

package com.azure.resourcemanager.securityinsights.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.securityinsights.fluent.models.RelationInner;
import com.azure.resourcemanager.securityinsights.models.Relation;

public final class RelationImpl implements Relation, Relation.Definition, Relation.Update {
    private RelationInner innerObject;

    private final com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager;

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

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

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

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

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.securityinsights.SecurityInsightsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String workspaceName;

    private String bookmarkId;

    private String relationName;

    public RelationImpl withExistingBookmark(String resourceGroupName, String workspaceName, String bookmarkId) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        this.bookmarkId = bookmarkId;
        return this;
    }

    public Relation create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBookmarkRelations()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, bookmarkId, relationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Relation create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBookmarkRelations()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, bookmarkId, relationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    RelationImpl(String name, com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerObject = new RelationInner();
        this.serviceManager = serviceManager;
        this.relationName = name;
    }

    public RelationImpl update() {
        return this;
    }

    public Relation apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBookmarkRelations()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, bookmarkId, relationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Relation apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBookmarkRelations()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, bookmarkId, relationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    RelationImpl(
        RelationInner innerObject, com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.workspaceName = Utils.getValueFromIdByName(innerObject.id(), "workspaces");
        this.bookmarkId = Utils.getValueFromIdByName(innerObject.id(), "bookmarks");
        this.relationName = Utils.getValueFromIdByName(innerObject.id(), "relations");
    }

    public Relation refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBookmarkRelations()
                .getWithResponse(resourceGroupName, workspaceName, bookmarkId, relationName, Context.NONE)
                .getValue();
        return this;
    }

    public Relation refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBookmarkRelations()
                .getWithResponse(resourceGroupName, workspaceName, bookmarkId, relationName, context)
                .getValue();
        return this;
    }

    public RelationImpl withEtag(String etag) {
        this.innerModel().withEtag(etag);
        return this;
    }

    public RelationImpl withRelatedResourceId(String relatedResourceId) {
        this.innerModel().withRelatedResourceId(relatedResourceId);
        return this;
    }
}
