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

package com.azure.resourcemanager.videoanalyzer.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.videoanalyzer.fluent.models.PipelineTopologyInner;
import com.azure.resourcemanager.videoanalyzer.models.Kind;
import com.azure.resourcemanager.videoanalyzer.models.ParameterDeclaration;
import com.azure.resourcemanager.videoanalyzer.models.PipelineTopology;
import com.azure.resourcemanager.videoanalyzer.models.PipelineTopologyUpdate;
import com.azure.resourcemanager.videoanalyzer.models.ProcessorNodeBase;
import com.azure.resourcemanager.videoanalyzer.models.SinkNodeBase;
import com.azure.resourcemanager.videoanalyzer.models.Sku;
import com.azure.resourcemanager.videoanalyzer.models.SourceNodeBase;
import java.util.Collections;
import java.util.List;

public final class PipelineTopologyImpl
    implements PipelineTopology, PipelineTopology.Definition, PipelineTopology.Update {
    private PipelineTopologyInner innerObject;

    private final com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager serviceManager;

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

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

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

    public Kind kind() {
        return this.innerModel().kind();
    }

    public Sku sku() {
        return this.innerModel().sku();
    }

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

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String accountName;

    private String pipelineTopologyName;

    private PipelineTopologyUpdate updateParameters;

    public PipelineTopologyImpl withExistingVideoAnalyzer(String resourceGroupName, String accountName) {
        this.resourceGroupName = resourceGroupName;
        this.accountName = accountName;
        return this;
    }

    public PipelineTopology create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPipelineTopologies()
                .createOrUpdateWithResponse(
                    resourceGroupName, accountName, pipelineTopologyName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public PipelineTopology create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPipelineTopologies()
                .createOrUpdateWithResponse(
                    resourceGroupName, accountName, pipelineTopologyName, this.innerModel(), context)
                .getValue();
        return this;
    }

    PipelineTopologyImpl(String name, com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager serviceManager) {
        this.innerObject = new PipelineTopologyInner();
        this.serviceManager = serviceManager;
        this.pipelineTopologyName = name;
    }

    public PipelineTopologyImpl update() {
        this.updateParameters = new PipelineTopologyUpdate();
        return this;
    }

    public PipelineTopology apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPipelineTopologies()
                .updateWithResponse(
                    resourceGroupName, accountName, pipelineTopologyName, updateParameters, Context.NONE)
                .getValue();
        return this;
    }

    public PipelineTopology apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPipelineTopologies()
                .updateWithResponse(resourceGroupName, accountName, pipelineTopologyName, updateParameters, context)
                .getValue();
        return this;
    }

    PipelineTopologyImpl(
        PipelineTopologyInner innerObject,
        com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.accountName = Utils.getValueFromIdByName(innerObject.id(), "videoAnalyzers");
        this.pipelineTopologyName = Utils.getValueFromIdByName(innerObject.id(), "pipelineTopologies");
    }

    public PipelineTopology refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPipelineTopologies()
                .getWithResponse(resourceGroupName, accountName, pipelineTopologyName, Context.NONE)
                .getValue();
        return this;
    }

    public PipelineTopology refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPipelineTopologies()
                .getWithResponse(resourceGroupName, accountName, pipelineTopologyName, context)
                .getValue();
        return this;
    }

    public PipelineTopologyImpl withKind(Kind kind) {
        if (isInCreateMode()) {
            this.innerModel().withKind(kind);
            return this;
        } else {
            this.updateParameters.withKind(kind);
            return this;
        }
    }

    public PipelineTopologyImpl withSku(Sku sku) {
        if (isInCreateMode()) {
            this.innerModel().withSku(sku);
            return this;
        } else {
            this.updateParameters.withSku(sku);
            return this;
        }
    }

    public PipelineTopologyImpl withDescription(String description) {
        if (isInCreateMode()) {
            this.innerModel().withDescription(description);
            return this;
        } else {
            this.updateParameters.withDescription(description);
            return this;
        }
    }

    public PipelineTopologyImpl withParameters(List<ParameterDeclaration> parameters) {
        if (isInCreateMode()) {
            this.innerModel().withParameters(parameters);
            return this;
        } else {
            this.updateParameters.withParameters(parameters);
            return this;
        }
    }

    public PipelineTopologyImpl withSources(List<SourceNodeBase> sources) {
        if (isInCreateMode()) {
            this.innerModel().withSources(sources);
            return this;
        } else {
            this.updateParameters.withSources(sources);
            return this;
        }
    }

    public PipelineTopologyImpl withProcessors(List<ProcessorNodeBase> processors) {
        if (isInCreateMode()) {
            this.innerModel().withProcessors(processors);
            return this;
        } else {
            this.updateParameters.withProcessors(processors);
            return this;
        }
    }

    public PipelineTopologyImpl withSinks(List<SinkNodeBase> sinks) {
        if (isInCreateMode()) {
            this.innerModel().withSinks(sinks);
            return this;
        } else {
            this.updateParameters.withSinks(sinks);
            return this;
        }
    }

    private boolean isInCreateMode() {
        return this.innerModel().id() == null;
    }
}
