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

package com.azure.resourcemanager.logic.implementation;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.logic.fluent.WorkflowVersionsClient;
import com.azure.resourcemanager.logic.fluent.models.WorkflowVersionInner;
import com.azure.resourcemanager.logic.models.WorkflowVersion;
import com.azure.resourcemanager.logic.models.WorkflowVersions;

public final class WorkflowVersionsImpl implements WorkflowVersions {
    private static final ClientLogger LOGGER = new ClientLogger(WorkflowVersionsImpl.class);

    private final WorkflowVersionsClient innerClient;

    private final com.azure.resourcemanager.logic.LogicManager serviceManager;

    public WorkflowVersionsImpl(
        WorkflowVersionsClient innerClient, com.azure.resourcemanager.logic.LogicManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<WorkflowVersion> list(String resourceGroupName, String workflowName) {
        PagedIterable<WorkflowVersionInner> inner = this.serviceClient().list(resourceGroupName, workflowName);
        return Utils.mapPage(inner, inner1 -> new WorkflowVersionImpl(inner1, this.manager()));
    }

    public PagedIterable<WorkflowVersion> list(
        String resourceGroupName, String workflowName, Integer top, Context context) {
        PagedIterable<WorkflowVersionInner> inner =
            this.serviceClient().list(resourceGroupName, workflowName, top, context);
        return Utils.mapPage(inner, inner1 -> new WorkflowVersionImpl(inner1, this.manager()));
    }

    public Response<WorkflowVersion> getWithResponse(
        String resourceGroupName, String workflowName, String versionId, Context context) {
        Response<WorkflowVersionInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, workflowName, versionId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new WorkflowVersionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public WorkflowVersion get(String resourceGroupName, String workflowName, String versionId) {
        WorkflowVersionInner inner = this.serviceClient().get(resourceGroupName, workflowName, versionId);
        if (inner != null) {
            return new WorkflowVersionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    private WorkflowVersionsClient serviceClient() {
        return this.innerClient;
    }

    private com.azure.resourcemanager.logic.LogicManager manager() {
        return this.serviceManager;
    }
}
