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

package com.azure.resourcemanager.devcenter.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.devcenter.fluent.ProjectAllowedEnvironmentTypesClient;
import com.azure.resourcemanager.devcenter.fluent.models.AllowedEnvironmentTypeInner;
import com.azure.resourcemanager.devcenter.models.AllowedEnvironmentType;
import com.azure.resourcemanager.devcenter.models.ProjectAllowedEnvironmentTypes;

public final class ProjectAllowedEnvironmentTypesImpl implements ProjectAllowedEnvironmentTypes {
    private static final ClientLogger LOGGER = new ClientLogger(ProjectAllowedEnvironmentTypesImpl.class);

    private final ProjectAllowedEnvironmentTypesClient innerClient;

    private final com.azure.resourcemanager.devcenter.DevCenterManager serviceManager;

    public ProjectAllowedEnvironmentTypesImpl(
        ProjectAllowedEnvironmentTypesClient innerClient,
        com.azure.resourcemanager.devcenter.DevCenterManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<AllowedEnvironmentType> list(String resourceGroupName, String projectName) {
        PagedIterable<AllowedEnvironmentTypeInner> inner = this.serviceClient().list(resourceGroupName, projectName);
        return Utils.mapPage(inner, inner1 -> new AllowedEnvironmentTypeImpl(inner1, this.manager()));
    }

    public PagedIterable<AllowedEnvironmentType> list(
        String resourceGroupName, String projectName, Integer top, Context context) {
        PagedIterable<AllowedEnvironmentTypeInner> inner =
            this.serviceClient().list(resourceGroupName, projectName, top, context);
        return Utils.mapPage(inner, inner1 -> new AllowedEnvironmentTypeImpl(inner1, this.manager()));
    }

    public Response<AllowedEnvironmentType> getWithResponse(
        String resourceGroupName, String projectName, String environmentTypeName, Context context) {
        Response<AllowedEnvironmentTypeInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, projectName, environmentTypeName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new AllowedEnvironmentTypeImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public AllowedEnvironmentType get(String resourceGroupName, String projectName, String environmentTypeName) {
        AllowedEnvironmentTypeInner inner =
            this.serviceClient().get(resourceGroupName, projectName, environmentTypeName);
        if (inner != null) {
            return new AllowedEnvironmentTypeImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.devcenter.DevCenterManager manager() {
        return this.serviceManager;
    }
}
