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

package com.azure.resourcemanager.resourcehealth.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.resourcehealth.fluent.ChildAvailabilityStatusesClient;
import com.azure.resourcemanager.resourcehealth.fluent.models.AvailabilityStatusInner;
import com.azure.resourcemanager.resourcehealth.models.AvailabilityStatus;
import com.azure.resourcemanager.resourcehealth.models.ChildAvailabilityStatuses;

public final class ChildAvailabilityStatusesImpl implements ChildAvailabilityStatuses {
    private static final ClientLogger LOGGER = new ClientLogger(ChildAvailabilityStatusesImpl.class);

    private final ChildAvailabilityStatusesClient innerClient;

    private final com.azure.resourcemanager.resourcehealth.ResourceHealthManager serviceManager;

    public ChildAvailabilityStatusesImpl(
        ChildAvailabilityStatusesClient innerClient,
        com.azure.resourcemanager.resourcehealth.ResourceHealthManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<AvailabilityStatus> getByResourceWithResponse(
        String resourceUri, String filter, String expand, Context context) {
        Response<AvailabilityStatusInner> inner =
            this.serviceClient().getByResourceWithResponse(resourceUri, filter, expand, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new AvailabilityStatusImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public AvailabilityStatus getByResource(String resourceUri) {
        AvailabilityStatusInner inner = this.serviceClient().getByResource(resourceUri);
        if (inner != null) {
            return new AvailabilityStatusImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<AvailabilityStatus> list(String resourceUri) {
        PagedIterable<AvailabilityStatusInner> inner = this.serviceClient().list(resourceUri);
        return Utils.mapPage(inner, inner1 -> new AvailabilityStatusImpl(inner1, this.manager()));
    }

    public PagedIterable<AvailabilityStatus> list(String resourceUri, String filter, String expand, Context context) {
        PagedIterable<AvailabilityStatusInner> inner = this.serviceClient().list(resourceUri, filter, expand, context);
        return Utils.mapPage(inner, inner1 -> new AvailabilityStatusImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.resourcehealth.ResourceHealthManager manager() {
        return this.serviceManager;
    }
}
