// 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.SourceControlSyncJobsClient;
import com.azure.resourcemanager.automation.fluent.models.SourceControlSyncJobByIdInner;
import com.azure.resourcemanager.automation.fluent.models.SourceControlSyncJobInner;
import com.azure.resourcemanager.automation.models.SourceControlSyncJob;
import com.azure.resourcemanager.automation.models.SourceControlSyncJobById;
import com.azure.resourcemanager.automation.models.SourceControlSyncJobs;
import java.util.UUID;

public final class SourceControlSyncJobsImpl implements SourceControlSyncJobs {
    private static final ClientLogger LOGGER = new ClientLogger(SourceControlSyncJobsImpl.class);

    private final SourceControlSyncJobsClient innerClient;

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

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

    public SourceControlSyncJobById get(
        String resourceGroupName, String automationAccountName, String sourceControlName, UUID sourceControlSyncJobId) {
        SourceControlSyncJobByIdInner inner =
            this
                .serviceClient()
                .get(resourceGroupName, automationAccountName, sourceControlName, sourceControlSyncJobId);
        if (inner != null) {
            return new SourceControlSyncJobByIdImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SourceControlSyncJobById> getWithResponse(
        String resourceGroupName,
        String automationAccountName,
        String sourceControlName,
        UUID sourceControlSyncJobId,
        Context context) {
        Response<SourceControlSyncJobByIdInner> inner =
            this
                .serviceClient()
                .getWithResponse(
                    resourceGroupName, automationAccountName, sourceControlName, sourceControlSyncJobId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SourceControlSyncJobByIdImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PagedIterable<SourceControlSyncJob> listByAutomationAccount(
        String resourceGroupName, String automationAccountName, String sourceControlName) {
        PagedIterable<SourceControlSyncJobInner> inner =
            this.serviceClient().listByAutomationAccount(resourceGroupName, automationAccountName, sourceControlName);
        return Utils.mapPage(inner, inner1 -> new SourceControlSyncJobImpl(inner1, this.manager()));
    }

    public PagedIterable<SourceControlSyncJob> listByAutomationAccount(
        String resourceGroupName,
        String automationAccountName,
        String sourceControlName,
        String filter,
        Context context) {
        PagedIterable<SourceControlSyncJobInner> inner =
            this
                .serviceClient()
                .listByAutomationAccount(resourceGroupName, automationAccountName, sourceControlName, filter, context);
        return Utils.mapPage(inner, inner1 -> new SourceControlSyncJobImpl(inner1, this.manager()));
    }

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

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

    public SourceControlSyncJobImpl define(UUID name) {
        return new SourceControlSyncJobImpl(name, this.manager());
    }
}
