// 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.WorkflowRunActionRequestHistoriesClient;
import com.azure.resourcemanager.logic.fluent.models.RequestHistoryInner;
import com.azure.resourcemanager.logic.models.RequestHistory;
import com.azure.resourcemanager.logic.models.WorkflowRunActionRequestHistories;

public final class WorkflowRunActionRequestHistoriesImpl implements WorkflowRunActionRequestHistories {
    private static final ClientLogger LOGGER = new ClientLogger(WorkflowRunActionRequestHistoriesImpl.class);

    private final WorkflowRunActionRequestHistoriesClient innerClient;

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

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

    public PagedIterable<RequestHistory> list(
        String resourceGroupName, String workflowName, String runName, String actionName) {
        PagedIterable<RequestHistoryInner> inner =
            this.serviceClient().list(resourceGroupName, workflowName, runName, actionName);
        return Utils.mapPage(inner, inner1 -> new RequestHistoryImpl(inner1, this.manager()));
    }

    public PagedIterable<RequestHistory> list(
        String resourceGroupName, String workflowName, String runName, String actionName, Context context) {
        PagedIterable<RequestHistoryInner> inner =
            this.serviceClient().list(resourceGroupName, workflowName, runName, actionName, context);
        return Utils.mapPage(inner, inner1 -> new RequestHistoryImpl(inner1, this.manager()));
    }

    public Response<RequestHistory> getWithResponse(
        String resourceGroupName,
        String workflowName,
        String runName,
        String actionName,
        String requestHistoryName,
        Context context) {
        Response<RequestHistoryInner> inner =
            this
                .serviceClient()
                .getWithResponse(resourceGroupName, workflowName, runName, actionName, requestHistoryName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RequestHistoryImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public RequestHistory get(
        String resourceGroupName, String workflowName, String runName, String actionName, String requestHistoryName) {
        RequestHistoryInner inner =
            this.serviceClient().get(resourceGroupName, workflowName, runName, actionName, requestHistoryName);
        if (inner != null) {
            return new RequestHistoryImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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