// 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.IncidentCommentInner;
import com.azure.resourcemanager.securityinsights.models.ClientInfo;
import com.azure.resourcemanager.securityinsights.models.IncidentComment;
import java.time.OffsetDateTime;

public final class IncidentCommentImpl implements IncidentComment, IncidentComment.Definition, IncidentComment.Update {
    private IncidentCommentInner 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 OffsetDateTime createdTimeUtc() {
        return this.innerModel().createdTimeUtc();
    }

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

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

    public ClientInfo author() {
        return this.innerModel().author();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private String incidentId;

    private String incidentCommentId;

    public IncidentCommentImpl withExistingIncident(String resourceGroupName, String workspaceName, String incidentId) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        this.incidentId = incidentId;
        return this;
    }

    public IncidentComment create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIncidentComments()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, incidentId, incidentCommentId, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public IncidentComment create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIncidentComments()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, incidentId, incidentCommentId, this.innerModel(), context)
                .getValue();
        return this;
    }

    IncidentCommentImpl(
        String name, com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerObject = new IncidentCommentInner();
        this.serviceManager = serviceManager;
        this.incidentCommentId = name;
    }

    public IncidentCommentImpl update() {
        return this;
    }

    public IncidentComment apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIncidentComments()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, incidentId, incidentCommentId, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public IncidentComment apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIncidentComments()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, incidentId, incidentCommentId, this.innerModel(), context)
                .getValue();
        return this;
    }

    IncidentCommentImpl(
        IncidentCommentInner 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.incidentId = Utils.getValueFromIdByName(innerObject.id(), "incidents");
        this.incidentCommentId = Utils.getValueFromIdByName(innerObject.id(), "comments");
    }

    public IncidentComment refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIncidentComments()
                .getWithResponse(resourceGroupName, workspaceName, incidentId, incidentCommentId, Context.NONE)
                .getValue();
        return this;
    }

    public IncidentComment refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIncidentComments()
                .getWithResponse(resourceGroupName, workspaceName, incidentId, incidentCommentId, context)
                .getValue();
        return this;
    }

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

    public IncidentCommentImpl withMessage(String message) {
        this.innerModel().withMessage(message);
        return this;
    }
}
