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

package com.azure.resourcemanager.policyinsights.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.policyinsights.fluent.PolicyMetadatasClient;
import com.azure.resourcemanager.policyinsights.fluent.models.PolicyMetadataInner;
import com.azure.resourcemanager.policyinsights.fluent.models.SlimPolicyMetadataInner;
import com.azure.resourcemanager.policyinsights.models.PolicyMetadata;
import com.azure.resourcemanager.policyinsights.models.PolicyMetadatas;
import com.azure.resourcemanager.policyinsights.models.SlimPolicyMetadata;

public final class PolicyMetadatasImpl implements PolicyMetadatas {
    private static final ClientLogger LOGGER = new ClientLogger(PolicyMetadatasImpl.class);

    private final PolicyMetadatasClient innerClient;

    private final com.azure.resourcemanager.policyinsights.PolicyInsightsManager serviceManager;

    public PolicyMetadatasImpl(
        PolicyMetadatasClient innerClient,
        com.azure.resourcemanager.policyinsights.PolicyInsightsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<PolicyMetadata> getResourceWithResponse(String resourceName, Context context) {
        Response<PolicyMetadataInner> inner = this.serviceClient().getResourceWithResponse(resourceName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new PolicyMetadataImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PolicyMetadata getResource(String resourceName) {
        PolicyMetadataInner inner = this.serviceClient().getResource(resourceName);
        if (inner != null) {
            return new PolicyMetadataImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<SlimPolicyMetadata> list() {
        PagedIterable<SlimPolicyMetadataInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new SlimPolicyMetadataImpl(inner1, this.manager()));
    }

    public PagedIterable<SlimPolicyMetadata> list(Integer top, Context context) {
        PagedIterable<SlimPolicyMetadataInner> inner = this.serviceClient().list(top, context);
        return Utils.mapPage(inner, inner1 -> new SlimPolicyMetadataImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.policyinsights.PolicyInsightsManager manager() {
        return this.serviceManager;
    }
}
