// 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.ImagesClient;
import com.azure.resourcemanager.devcenter.fluent.models.ImageInner;
import com.azure.resourcemanager.devcenter.models.Image;
import com.azure.resourcemanager.devcenter.models.Images;

public final class ImagesImpl implements Images {
    private static final ClientLogger LOGGER = new ClientLogger(ImagesImpl.class);

    private final ImagesClient innerClient;

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

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

    public PagedIterable<Image> listByDevCenter(String resourceGroupName, String devCenterName) {
        PagedIterable<ImageInner> inner = this.serviceClient().listByDevCenter(resourceGroupName, devCenterName);
        return Utils.mapPage(inner, inner1 -> new ImageImpl(inner1, this.manager()));
    }

    public PagedIterable<Image> listByDevCenter(
        String resourceGroupName, String devCenterName, Integer top, Context context) {
        PagedIterable<ImageInner> inner =
            this.serviceClient().listByDevCenter(resourceGroupName, devCenterName, top, context);
        return Utils.mapPage(inner, inner1 -> new ImageImpl(inner1, this.manager()));
    }

    public PagedIterable<Image> listByGallery(String resourceGroupName, String devCenterName, String galleryName) {
        PagedIterable<ImageInner> inner =
            this.serviceClient().listByGallery(resourceGroupName, devCenterName, galleryName);
        return Utils.mapPage(inner, inner1 -> new ImageImpl(inner1, this.manager()));
    }

    public PagedIterable<Image> listByGallery(
        String resourceGroupName, String devCenterName, String galleryName, Integer top, Context context) {
        PagedIterable<ImageInner> inner =
            this.serviceClient().listByGallery(resourceGroupName, devCenterName, galleryName, top, context);
        return Utils.mapPage(inner, inner1 -> new ImageImpl(inner1, this.manager()));
    }

    public Response<Image> getWithResponse(
        String resourceGroupName, String devCenterName, String galleryName, String imageName, Context context) {
        Response<ImageInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, devCenterName, galleryName, imageName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ImageImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Image get(String resourceGroupName, String devCenterName, String galleryName, String imageName) {
        ImageInner inner = this.serviceClient().get(resourceGroupName, devCenterName, galleryName, imageName);
        if (inner != null) {
            return new ImageImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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