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

package com.azure.resourcemanager.cognitiveservices.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.cognitiveservices.fluent.DeletedAccountsClient;
import com.azure.resourcemanager.cognitiveservices.fluent.models.AccountInner;
import com.azure.resourcemanager.cognitiveservices.models.Account;
import com.azure.resourcemanager.cognitiveservices.models.DeletedAccounts;

public final class DeletedAccountsImpl implements DeletedAccounts {
    private static final ClientLogger LOGGER = new ClientLogger(DeletedAccountsImpl.class);

    private final DeletedAccountsClient innerClient;

    private final com.azure.resourcemanager.cognitiveservices.CognitiveServicesManager serviceManager;

    public DeletedAccountsImpl(
        DeletedAccountsClient innerClient,
        com.azure.resourcemanager.cognitiveservices.CognitiveServicesManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<Account> getWithResponse(
        String location, String resourceGroupName, String accountName, Context context) {
        Response<AccountInner> inner =
            this.serviceClient().getWithResponse(location, resourceGroupName, accountName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new AccountImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Account get(String location, String resourceGroupName, String accountName) {
        AccountInner inner = this.serviceClient().get(location, resourceGroupName, accountName);
        if (inner != null) {
            return new AccountImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void purge(String location, String resourceGroupName, String accountName) {
        this.serviceClient().purge(location, resourceGroupName, accountName);
    }

    public void purge(String location, String resourceGroupName, String accountName, Context context) {
        this.serviceClient().purge(location, resourceGroupName, accountName, context);
    }

    public PagedIterable<Account> list() {
        PagedIterable<AccountInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new AccountImpl(inner1, this.manager()));
    }

    public PagedIterable<Account> list(Context context) {
        PagedIterable<AccountInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new AccountImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.cognitiveservices.CognitiveServicesManager manager() {
        return this.serviceManager;
    }
}
