// 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.WatchlistInner;
import com.azure.resourcemanager.securityinsights.models.SourceType;
import com.azure.resourcemanager.securityinsights.models.UserInfo;
import com.azure.resourcemanager.securityinsights.models.Watchlist;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;

public final class WatchlistImpl implements Watchlist, Watchlist.Definition, Watchlist.Update {
    private WatchlistInner 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 watchlistId() {
        return this.innerModel().watchlistId();
    }

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

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

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

    public SourceType sourceType() {
        return this.innerModel().sourceType();
    }

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

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

    public UserInfo createdBy() {
        return this.innerModel().createdBy();
    }

    public UserInfo updatedBy() {
        return this.innerModel().updatedBy();
    }

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

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

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

    public Boolean isDeleted() {
        return this.innerModel().isDeleted();
    }

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

    public Duration defaultDuration() {
        return this.innerModel().defaultDuration();
    }

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

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private String watchlistAlias;

    public WatchlistImpl withExistingWorkspace(String resourceGroupName, String workspaceName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        return this;
    }

    public Watchlist create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchlists()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, watchlistAlias, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Watchlist create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchlists()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, watchlistAlias, this.innerModel(), context)
                .getValue();
        return this;
    }

    WatchlistImpl(String name, com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerObject = new WatchlistInner();
        this.serviceManager = serviceManager;
        this.watchlistAlias = name;
    }

    public WatchlistImpl update() {
        return this;
    }

    public Watchlist apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchlists()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, watchlistAlias, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Watchlist apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchlists()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, watchlistAlias, this.innerModel(), context)
                .getValue();
        return this;
    }

    WatchlistImpl(
        WatchlistInner 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.watchlistAlias = Utils.getValueFromIdByName(innerObject.id(), "watchlists");
    }

    public Watchlist refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchlists()
                .getWithResponse(resourceGroupName, workspaceName, watchlistAlias, Context.NONE)
                .getValue();
        return this;
    }

    public Watchlist refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchlists()
                .getWithResponse(resourceGroupName, workspaceName, watchlistAlias, context)
                .getValue();
        return this;
    }

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

    public WatchlistImpl withWatchlistId(String watchlistId) {
        this.innerModel().withWatchlistId(watchlistId);
        return this;
    }

    public WatchlistImpl withDisplayName(String displayName) {
        this.innerModel().withDisplayName(displayName);
        return this;
    }

    public WatchlistImpl withProvider(String provider) {
        this.innerModel().withProvider(provider);
        return this;
    }

    public WatchlistImpl withSource(String source) {
        this.innerModel().withSource(source);
        return this;
    }

    public WatchlistImpl withSourceType(SourceType sourceType) {
        this.innerModel().withSourceType(sourceType);
        return this;
    }

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

    public WatchlistImpl withUpdated(OffsetDateTime updated) {
        this.innerModel().withUpdated(updated);
        return this;
    }

    public WatchlistImpl withCreatedBy(UserInfo createdBy) {
        this.innerModel().withCreatedBy(createdBy);
        return this;
    }

    public WatchlistImpl withUpdatedBy(UserInfo updatedBy) {
        this.innerModel().withUpdatedBy(updatedBy);
        return this;
    }

    public WatchlistImpl withDescription(String description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public WatchlistImpl withWatchlistType(String watchlistType) {
        this.innerModel().withWatchlistType(watchlistType);
        return this;
    }

    public WatchlistImpl withWatchlistAlias(String watchlistAlias) {
        this.innerModel().withWatchlistAlias(watchlistAlias);
        return this;
    }

    public WatchlistImpl withIsDeleted(Boolean isDeleted) {
        this.innerModel().withIsDeleted(isDeleted);
        return this;
    }

    public WatchlistImpl withLabels(List<String> labels) {
        this.innerModel().withLabels(labels);
        return this;
    }

    public WatchlistImpl withDefaultDuration(Duration defaultDuration) {
        this.innerModel().withDefaultDuration(defaultDuration);
        return this;
    }

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

    public WatchlistImpl withNumberOfLinesToSkip(Integer numberOfLinesToSkip) {
        this.innerModel().withNumberOfLinesToSkip(numberOfLinesToSkip);
        return this;
    }

    public WatchlistImpl withRawContent(String rawContent) {
        this.innerModel().withRawContent(rawContent);
        return this;
    }

    public WatchlistImpl withItemsSearchKey(String itemsSearchKey) {
        this.innerModel().withItemsSearchKey(itemsSearchKey);
        return this;
    }

    public WatchlistImpl withContentType(String contentType) {
        this.innerModel().withContentType(contentType);
        return this;
    }

    public WatchlistImpl withUploadStatus(String uploadStatus) {
        this.innerModel().withUploadStatus(uploadStatus);
        return this;
    }
}
