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

package com.azure.resourcemanager.automation.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.automation.fluent.ActivitiesClient;
import com.azure.resourcemanager.automation.fluent.models.ActivityInner;
import com.azure.resourcemanager.automation.models.Activities;
import com.azure.resourcemanager.automation.models.Activity;

public final class ActivitiesImpl implements Activities {
    private static final ClientLogger LOGGER = new ClientLogger(ActivitiesImpl.class);

    private final ActivitiesClient innerClient;

    private final com.azure.resourcemanager.automation.AutomationManager serviceManager;

    public ActivitiesImpl(
        ActivitiesClient innerClient, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Activity get(
        String resourceGroupName, String automationAccountName, String moduleName, String activityName) {
        ActivityInner inner =
            this.serviceClient().get(resourceGroupName, automationAccountName, moduleName, activityName);
        if (inner != null) {
            return new ActivityImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Activity> getWithResponse(
        String resourceGroupName,
        String automationAccountName,
        String moduleName,
        String activityName,
        Context context) {
        Response<ActivityInner> inner =
            this
                .serviceClient()
                .getWithResponse(resourceGroupName, automationAccountName, moduleName, activityName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ActivityImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PagedIterable<Activity> listByModule(
        String resourceGroupName, String automationAccountName, String moduleName) {
        PagedIterable<ActivityInner> inner =
            this.serviceClient().listByModule(resourceGroupName, automationAccountName, moduleName);
        return Utils.mapPage(inner, inner1 -> new ActivityImpl(inner1, this.manager()));
    }

    public PagedIterable<Activity> listByModule(
        String resourceGroupName, String automationAccountName, String moduleName, Context context) {
        PagedIterable<ActivityInner> inner =
            this.serviceClient().listByModule(resourceGroupName, automationAccountName, moduleName, context);
        return Utils.mapPage(inner, inner1 -> new ActivityImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.automation.AutomationManager manager() {
        return this.serviceManager;
    }
}
