// 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.ImageVersionsClient;
import com.azure.resourcemanager.devcenter.fluent.models.ImageVersionInner;
import com.azure.resourcemanager.devcenter.models.ImageVersion;
import com.azure.resourcemanager.devcenter.models.ImageVersions;

public final class ImageVersionsImpl implements ImageVersions {
    private static final ClientLogger LOGGER = new ClientLogger(ImageVersionsImpl.class);

    private final ImageVersionsClient innerClient;

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

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

    public PagedIterable<ImageVersion> listByImage(
        String resourceGroupName, String devCenterName, String galleryName, String imageName) {
        PagedIterable<ImageVersionInner> inner =
            this.serviceClient().listByImage(resourceGroupName, devCenterName, galleryName, imageName);
        return Utils.mapPage(inner, inner1 -> new ImageVersionImpl(inner1, this.manager()));
    }

    public PagedIterable<ImageVersion> listByImage(
        String resourceGroupName, String devCenterName, String galleryName, String imageName, Context context) {
        PagedIterable<ImageVersionInner> inner =
            this.serviceClient().listByImage(resourceGroupName, devCenterName, galleryName, imageName, context);
        return Utils.mapPage(inner, inner1 -> new ImageVersionImpl(inner1, this.manager()));
    }

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

    public ImageVersion get(
        String resourceGroupName, String devCenterName, String galleryName, String imageName, String versionName) {
        ImageVersionInner inner =
            this.serviceClient().get(resourceGroupName, devCenterName, galleryName, imageName, versionName);
        if (inner != null) {
            return new ImageVersionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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