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

package com.azure.resourcemanager.devtestlabs.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.devtestlabs.fluent.ArmTemplatesClient;
import com.azure.resourcemanager.devtestlabs.fluent.models.ArmTemplateInner;
import com.azure.resourcemanager.devtestlabs.models.ArmTemplate;
import com.azure.resourcemanager.devtestlabs.models.ArmTemplates;

public final class ArmTemplatesImpl implements ArmTemplates {
    private static final ClientLogger LOGGER = new ClientLogger(ArmTemplatesImpl.class);

    private final ArmTemplatesClient innerClient;

    private final com.azure.resourcemanager.devtestlabs.DevTestLabsManager serviceManager;

    public ArmTemplatesImpl(
        ArmTemplatesClient innerClient, com.azure.resourcemanager.devtestlabs.DevTestLabsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<ArmTemplate> list(String resourceGroupName, String labName, String artifactSourceName) {
        PagedIterable<ArmTemplateInner> inner =
            this.serviceClient().list(resourceGroupName, labName, artifactSourceName);
        return Utils.mapPage(inner, inner1 -> new ArmTemplateImpl(inner1, this.manager()));
    }

    public PagedIterable<ArmTemplate> list(
        String resourceGroupName,
        String labName,
        String artifactSourceName,
        String expand,
        String filter,
        Integer top,
        String orderby,
        Context context) {
        PagedIterable<ArmTemplateInner> inner =
            this
                .serviceClient()
                .list(resourceGroupName, labName, artifactSourceName, expand, filter, top, orderby, context);
        return Utils.mapPage(inner, inner1 -> new ArmTemplateImpl(inner1, this.manager()));
    }

    public Response<ArmTemplate> getWithResponse(
        String resourceGroupName,
        String labName,
        String artifactSourceName,
        String name,
        String expand,
        Context context) {
        Response<ArmTemplateInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, labName, artifactSourceName, name, expand, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ArmTemplateImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ArmTemplate get(String resourceGroupName, String labName, String artifactSourceName, String name) {
        ArmTemplateInner inner = this.serviceClient().get(resourceGroupName, labName, artifactSourceName, name);
        if (inner != null) {
            return new ArmTemplateImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.devtestlabs.DevTestLabsManager manager() {
        return this.serviceManager;
    }
}
