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

package com.azure.resourcemanager.vmwarecloudsimple.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.vmwarecloudsimple.fluent.OperationsClient;
import com.azure.resourcemanager.vmwarecloudsimple.fluent.models.AvailableOperationInner;
import com.azure.resourcemanager.vmwarecloudsimple.fluent.models.OperationResourceInner;
import com.azure.resourcemanager.vmwarecloudsimple.models.AvailableOperation;
import com.azure.resourcemanager.vmwarecloudsimple.models.OperationResource;
import com.azure.resourcemanager.vmwarecloudsimple.models.Operations;
import com.azure.resourcemanager.vmwarecloudsimple.models.OperationsGetResponse;

public final class OperationsImpl implements Operations {
    private static final ClientLogger LOGGER = new ClientLogger(OperationsImpl.class);

    private final OperationsClient innerClient;

    private final com.azure.resourcemanager.vmwarecloudsimple.VMwareCloudSimpleManager serviceManager;

    public OperationsImpl(
        OperationsClient innerClient,
        com.azure.resourcemanager.vmwarecloudsimple.VMwareCloudSimpleManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<AvailableOperation> list() {
        PagedIterable<AvailableOperationInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new AvailableOperationImpl(inner1, this.manager()));
    }

    public PagedIterable<AvailableOperation> list(Context context) {
        PagedIterable<AvailableOperationInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new AvailableOperationImpl(inner1, this.manager()));
    }

    public Response<OperationResource> getWithResponse(
        String regionId, String referer, String operationId, Context context) {
        OperationsGetResponse inner = this.serviceClient().getWithResponse(regionId, referer, operationId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new OperationResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public OperationResource get(String regionId, String referer, String operationId) {
        OperationResourceInner inner = this.serviceClient().get(regionId, referer, operationId);
        if (inner != null) {
            return new OperationResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.vmwarecloudsimple.VMwareCloudSimpleManager manager() {
        return this.serviceManager;
    }
}
