/**
 * 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.
 * abc
 */

package com.microsoft.azure.management.apimanagement.v2019_01_01.implementation;

import com.microsoft.azure.arm.model.implementation.WrapperImpl;
import com.microsoft.azure.management.apimanagement.v2019_01_01.Regions;
import rx.functions.Func1;
import rx.Observable;
import com.microsoft.azure.Page;
import com.microsoft.azure.management.apimanagement.v2019_01_01.RegionContract;

class RegionsImpl extends WrapperImpl<RegionsInner> implements Regions {
    private final ApiManagementManager manager;

    RegionsImpl(ApiManagementManager manager) {
        super(manager.inner().regions());
        this.manager = manager;
    }

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

    @Override
    public Observable<RegionContract> listByServiceAsync(final String resourceGroupName, final String serviceName) {
        RegionsInner client = this.inner();
        return client.listByServiceAsync(resourceGroupName, serviceName)
        .flatMapIterable(new Func1<Page<RegionContractInner>, Iterable<RegionContractInner>>() {
            @Override
            public Iterable<RegionContractInner> call(Page<RegionContractInner> page) {
                return page.items();
            }
        })
        .map(new Func1<RegionContractInner, RegionContract>() {
            @Override
            public RegionContract call(RegionContractInner inner) {
                return new RegionContractImpl(inner, manager());
            }
        });
    }

}
