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

package com.azure.resourcemanager.reservations.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.reservations.fluent.ReservationsClient;
import com.azure.resourcemanager.reservations.fluent.models.AvailableScopePropertiesInner;
import com.azure.resourcemanager.reservations.fluent.models.ReservationResponseInner;
import com.azure.resourcemanager.reservations.models.AvailableScopeProperties;
import com.azure.resourcemanager.reservations.models.AvailableScopeRequest;
import com.azure.resourcemanager.reservations.models.MergeRequest;
import com.azure.resourcemanager.reservations.models.PatchModel;
import com.azure.resourcemanager.reservations.models.ReservationResponse;
import com.azure.resourcemanager.reservations.models.Reservations;
import com.azure.resourcemanager.reservations.models.SplitRequest;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public final class ReservationsImpl implements Reservations {
    private static final ClientLogger LOGGER = new ClientLogger(ReservationsImpl.class);

    private final ReservationsClient innerClient;

    private final com.azure.resourcemanager.reservations.ReservationsManager serviceManager;

    public ReservationsImpl(
        ReservationsClient innerClient, com.azure.resourcemanager.reservations.ReservationsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public AvailableScopeProperties availableScopes(
        String reservationOrderId, String reservationId, AvailableScopeRequest body) {
        AvailableScopePropertiesInner inner =
            this.serviceClient().availableScopes(reservationOrderId, reservationId, body);
        if (inner != null) {
            return new AvailableScopePropertiesImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public AvailableScopeProperties availableScopes(
        String reservationOrderId, String reservationId, AvailableScopeRequest body, Context context) {
        AvailableScopePropertiesInner inner =
            this.serviceClient().availableScopes(reservationOrderId, reservationId, body, context);
        if (inner != null) {
            return new AvailableScopePropertiesImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public List<ReservationResponse> split(String reservationOrderId, SplitRequest body) {
        List<ReservationResponseInner> inner = this.serviceClient().split(reservationOrderId, body);
        if (inner != null) {
            return Collections
                .unmodifiableList(
                    inner
                        .stream()
                        .map(inner1 -> new ReservationResponseImpl(inner1, this.manager()))
                        .collect(Collectors.toList()));
        } else {
            return Collections.emptyList();
        }
    }

    public List<ReservationResponse> split(String reservationOrderId, SplitRequest body, Context context) {
        List<ReservationResponseInner> inner = this.serviceClient().split(reservationOrderId, body, context);
        if (inner != null) {
            return Collections
                .unmodifiableList(
                    inner
                        .stream()
                        .map(inner1 -> new ReservationResponseImpl(inner1, this.manager()))
                        .collect(Collectors.toList()));
        } else {
            return Collections.emptyList();
        }
    }

    public List<ReservationResponse> merge(String reservationOrderId, MergeRequest body) {
        List<ReservationResponseInner> inner = this.serviceClient().merge(reservationOrderId, body);
        if (inner != null) {
            return Collections
                .unmodifiableList(
                    inner
                        .stream()
                        .map(inner1 -> new ReservationResponseImpl(inner1, this.manager()))
                        .collect(Collectors.toList()));
        } else {
            return Collections.emptyList();
        }
    }

    public List<ReservationResponse> merge(String reservationOrderId, MergeRequest body, Context context) {
        List<ReservationResponseInner> inner = this.serviceClient().merge(reservationOrderId, body, context);
        if (inner != null) {
            return Collections
                .unmodifiableList(
                    inner
                        .stream()
                        .map(inner1 -> new ReservationResponseImpl(inner1, this.manager()))
                        .collect(Collectors.toList()));
        } else {
            return Collections.emptyList();
        }
    }

    public PagedIterable<ReservationResponse> list(String reservationOrderId) {
        PagedIterable<ReservationResponseInner> inner = this.serviceClient().list(reservationOrderId);
        return Utils.mapPage(inner, inner1 -> new ReservationResponseImpl(inner1, this.manager()));
    }

    public PagedIterable<ReservationResponse> list(String reservationOrderId, Context context) {
        PagedIterable<ReservationResponseInner> inner = this.serviceClient().list(reservationOrderId, context);
        return Utils.mapPage(inner, inner1 -> new ReservationResponseImpl(inner1, this.manager()));
    }

    public Response<ReservationResponse> getWithResponse(
        String reservationOrderId, String reservationId, String expand, Context context) {
        Response<ReservationResponseInner> inner =
            this.serviceClient().getWithResponse(reservationOrderId, reservationId, expand, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ReservationResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ReservationResponse get(String reservationOrderId, String reservationId) {
        ReservationResponseInner inner = this.serviceClient().get(reservationOrderId, reservationId);
        if (inner != null) {
            return new ReservationResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public ReservationResponse update(String reservationOrderId, String reservationId, PatchModel parameters) {
        ReservationResponseInner inner = this.serviceClient().update(reservationOrderId, reservationId, parameters);
        if (inner != null) {
            return new ReservationResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public ReservationResponse update(
        String reservationOrderId, String reservationId, PatchModel parameters, Context context) {
        ReservationResponseInner inner =
            this.serviceClient().update(reservationOrderId, reservationId, parameters, context);
        if (inner != null) {
            return new ReservationResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> archiveWithResponse(String reservationOrderId, String reservationId, Context context) {
        return this.serviceClient().archiveWithResponse(reservationOrderId, reservationId, context);
    }

    public void archive(String reservationOrderId, String reservationId) {
        this.serviceClient().archive(reservationOrderId, reservationId);
    }

    public Response<Void> unarchiveWithResponse(String reservationOrderId, String reservationId, Context context) {
        return this.serviceClient().unarchiveWithResponse(reservationOrderId, reservationId, context);
    }

    public void unarchive(String reservationOrderId, String reservationId) {
        this.serviceClient().unarchive(reservationOrderId, reservationId);
    }

    public PagedIterable<ReservationResponse> listRevisions(String reservationOrderId, String reservationId) {
        PagedIterable<ReservationResponseInner> inner =
            this.serviceClient().listRevisions(reservationOrderId, reservationId);
        return Utils.mapPage(inner, inner1 -> new ReservationResponseImpl(inner1, this.manager()));
    }

    public PagedIterable<ReservationResponse> listRevisions(
        String reservationOrderId, String reservationId, Context context) {
        PagedIterable<ReservationResponseInner> inner =
            this.serviceClient().listRevisions(reservationOrderId, reservationId, context);
        return Utils.mapPage(inner, inner1 -> new ReservationResponseImpl(inner1, this.manager()));
    }

    public PagedIterable<ReservationResponse> listAll() {
        PagedIterable<ReservationResponseInner> inner = this.serviceClient().listAll();
        return Utils.mapPage(inner, inner1 -> new ReservationResponseImpl(inner1, this.manager()));
    }

    public PagedIterable<ReservationResponse> listAll(
        String filter,
        String orderby,
        String refreshSummary,
        Float skiptoken,
        String selectedState,
        Float take,
        Context context) {
        PagedIterable<ReservationResponseInner> inner =
            this.serviceClient().listAll(filter, orderby, refreshSummary, skiptoken, selectedState, take, context);
        return Utils.mapPage(inner, inner1 -> new ReservationResponseImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.reservations.ReservationsManager manager() {
        return this.serviceManager;
    }
}
