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

package com.azure.resourcemanager.apimanagement.implementation;

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.apimanagement.fluent.NotificationRecipientEmailsClient;
import com.azure.resourcemanager.apimanagement.fluent.models.RecipientEmailCollectionInner;
import com.azure.resourcemanager.apimanagement.fluent.models.RecipientEmailContractInner;
import com.azure.resourcemanager.apimanagement.models.NotificationName;
import com.azure.resourcemanager.apimanagement.models.NotificationRecipientEmails;
import com.azure.resourcemanager.apimanagement.models.RecipientEmailCollection;
import com.azure.resourcemanager.apimanagement.models.RecipientEmailContract;

public final class NotificationRecipientEmailsImpl implements NotificationRecipientEmails {
    private static final ClientLogger LOGGER = new ClientLogger(NotificationRecipientEmailsImpl.class);

    private final NotificationRecipientEmailsClient innerClient;

    private final com.azure.resourcemanager.apimanagement.ApiManagementManager serviceManager;

    public NotificationRecipientEmailsImpl(
        NotificationRecipientEmailsClient innerClient,
        com.azure.resourcemanager.apimanagement.ApiManagementManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public RecipientEmailCollection listByNotification(
        String resourceGroupName, String serviceName, NotificationName notificationName) {
        RecipientEmailCollectionInner inner =
            this.serviceClient().listByNotification(resourceGroupName, serviceName, notificationName);
        if (inner != null) {
            return new RecipientEmailCollectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<RecipientEmailCollection> listByNotificationWithResponse(
        String resourceGroupName, String serviceName, NotificationName notificationName, Context context) {
        Response<RecipientEmailCollectionInner> inner =
            this
                .serviceClient()
                .listByNotificationWithResponse(resourceGroupName, serviceName, notificationName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RecipientEmailCollectionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public boolean checkEntityExists(
        String resourceGroupName, String serviceName, NotificationName notificationName, String email) {
        return this.serviceClient().checkEntityExists(resourceGroupName, serviceName, notificationName, email);
    }

    public Response<Boolean> checkEntityExistsWithResponse(
        String resourceGroupName,
        String serviceName,
        NotificationName notificationName,
        String email,
        Context context) {
        return this
            .serviceClient()
            .checkEntityExistsWithResponse(resourceGroupName, serviceName, notificationName, email, context);
    }

    public RecipientEmailContract createOrUpdate(
        String resourceGroupName, String serviceName, NotificationName notificationName, String email) {
        RecipientEmailContractInner inner =
            this.serviceClient().createOrUpdate(resourceGroupName, serviceName, notificationName, email);
        if (inner != null) {
            return new RecipientEmailContractImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<RecipientEmailContract> createOrUpdateWithResponse(
        String resourceGroupName,
        String serviceName,
        NotificationName notificationName,
        String email,
        Context context) {
        Response<RecipientEmailContractInner> inner =
            this
                .serviceClient()
                .createOrUpdateWithResponse(resourceGroupName, serviceName, notificationName, email, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RecipientEmailContractImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public void delete(String resourceGroupName, String serviceName, NotificationName notificationName, String email) {
        this.serviceClient().delete(resourceGroupName, serviceName, notificationName, email);
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName,
        String serviceName,
        NotificationName notificationName,
        String email,
        Context context) {
        return this
            .serviceClient()
            .deleteWithResponse(resourceGroupName, serviceName, notificationName, email, context);
    }

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

    private com.azure.resourcemanager.apimanagement.ApiManagementManager manager() {
        return this.serviceManager;
    }
}
