/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 *
 */

package com.microsoft.azure.management.cosmosdb.v2019_12_12.implementation;

import com.microsoft.azure.arm.model.implementation.WrapperImpl;
import com.microsoft.azure.management.cosmosdb.v2019_12_12.PrivateLinkResources;
import rx.Observable;
import rx.functions.Func1;
import java.util.List;
import com.microsoft.azure.management.cosmosdb.v2019_12_12.PrivateLinkResource;

class PrivateLinkResourcesImpl extends WrapperImpl<PrivateLinkResourcesInner> implements PrivateLinkResources {
    private final CosmosDBManager manager;

    PrivateLinkResourcesImpl(CosmosDBManager manager) {
        super(manager.inner().privateLinkResources());
        this.manager = manager;
    }

    public CosmosDBManager manager() {
        return this.manager;
    }

    private PrivateLinkResourceImpl wrapModel(PrivateLinkResourceInner inner) {
        return  new PrivateLinkResourceImpl(inner, manager());
    }

    @Override
    public Observable<PrivateLinkResource> listByDatabaseAccountAsync(String resourceGroupName, String accountName) {
        PrivateLinkResourcesInner client = this.inner();
        return client.listByDatabaseAccountAsync(resourceGroupName, accountName)
        .flatMap(new Func1<List<PrivateLinkResourceInner>, Observable<PrivateLinkResourceInner>>() {
            @Override
            public Observable<PrivateLinkResourceInner> call(List<PrivateLinkResourceInner> innerList) {
                return Observable.from(innerList);
            }
        })
        .map(new Func1<PrivateLinkResourceInner, PrivateLinkResource>() {
            @Override
            public PrivateLinkResource call(PrivateLinkResourceInner inner) {
                return wrapModel(inner);
            }
        });
    }

    @Override
    public Observable<PrivateLinkResource> getAsync(String resourceGroupName, String accountName, String groupName) {
        PrivateLinkResourcesInner client = this.inner();
        return client.getAsync(resourceGroupName, accountName, groupName)
        .flatMap(new Func1<PrivateLinkResourceInner, Observable<PrivateLinkResource>>() {
            @Override
            public Observable<PrivateLinkResource> call(PrivateLinkResourceInner inner) {
                if (inner == null) {
                    return Observable.empty();
                } else {
                    return Observable.just((PrivateLinkResource)wrapModel(inner));
                }
            }
       });
    }

}
