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

package com.azure.resourcemanager.logic.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.logic.fluent.IntegrationAccountSchemasClient;
import com.azure.resourcemanager.logic.fluent.models.IntegrationAccountSchemaInner;
import com.azure.resourcemanager.logic.fluent.models.WorkflowTriggerCallbackUrlInner;
import com.azure.resourcemanager.logic.models.GetCallbackUrlParameters;
import com.azure.resourcemanager.logic.models.IntegrationAccountSchema;
import com.azure.resourcemanager.logic.models.IntegrationAccountSchemas;
import com.azure.resourcemanager.logic.models.WorkflowTriggerCallbackUrl;

public final class IntegrationAccountSchemasImpl implements IntegrationAccountSchemas {
    private static final ClientLogger LOGGER = new ClientLogger(IntegrationAccountSchemasImpl.class);

    private final IntegrationAccountSchemasClient innerClient;

    private final com.azure.resourcemanager.logic.LogicManager serviceManager;

    public IntegrationAccountSchemasImpl(
        IntegrationAccountSchemasClient innerClient, com.azure.resourcemanager.logic.LogicManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<IntegrationAccountSchema> list(String resourceGroupName, String integrationAccountName) {
        PagedIterable<IntegrationAccountSchemaInner> inner =
            this.serviceClient().list(resourceGroupName, integrationAccountName);
        return Utils.mapPage(inner, inner1 -> new IntegrationAccountSchemaImpl(inner1, this.manager()));
    }

    public PagedIterable<IntegrationAccountSchema> list(
        String resourceGroupName, String integrationAccountName, Integer top, String filter, Context context) {
        PagedIterable<IntegrationAccountSchemaInner> inner =
            this.serviceClient().list(resourceGroupName, integrationAccountName, top, filter, context);
        return Utils.mapPage(inner, inner1 -> new IntegrationAccountSchemaImpl(inner1, this.manager()));
    }

    public Response<IntegrationAccountSchema> getWithResponse(
        String resourceGroupName, String integrationAccountName, String schemaName, Context context) {
        Response<IntegrationAccountSchemaInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, integrationAccountName, schemaName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new IntegrationAccountSchemaImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public IntegrationAccountSchema get(String resourceGroupName, String integrationAccountName, String schemaName) {
        IntegrationAccountSchemaInner inner =
            this.serviceClient().get(resourceGroupName, integrationAccountName, schemaName);
        if (inner != null) {
            return new IntegrationAccountSchemaImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName, String integrationAccountName, String schemaName, Context context) {
        return this.serviceClient().deleteWithResponse(resourceGroupName, integrationAccountName, schemaName, context);
    }

    public void delete(String resourceGroupName, String integrationAccountName, String schemaName) {
        this.serviceClient().delete(resourceGroupName, integrationAccountName, schemaName);
    }

    public Response<WorkflowTriggerCallbackUrl> listContentCallbackUrlWithResponse(
        String resourceGroupName,
        String integrationAccountName,
        String schemaName,
        GetCallbackUrlParameters listContentCallbackUrl,
        Context context) {
        Response<WorkflowTriggerCallbackUrlInner> inner =
            this
                .serviceClient()
                .listContentCallbackUrlWithResponse(
                    resourceGroupName, integrationAccountName, schemaName, listContentCallbackUrl, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new WorkflowTriggerCallbackUrlImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public WorkflowTriggerCallbackUrl listContentCallbackUrl(
        String resourceGroupName,
        String integrationAccountName,
        String schemaName,
        GetCallbackUrlParameters listContentCallbackUrl) {
        WorkflowTriggerCallbackUrlInner inner =
            this
                .serviceClient()
                .listContentCallbackUrl(resourceGroupName, integrationAccountName, schemaName, listContentCallbackUrl);
        if (inner != null) {
            return new WorkflowTriggerCallbackUrlImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public IntegrationAccountSchema getById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String integrationAccountName = Utils.getValueFromIdByName(id, "integrationAccounts");
        if (integrationAccountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'integrationAccounts'.", id)));
        }
        String schemaName = Utils.getValueFromIdByName(id, "schemas");
        if (schemaName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'schemas'.", id)));
        }
        return this.getWithResponse(resourceGroupName, integrationAccountName, schemaName, Context.NONE).getValue();
    }

    public Response<IntegrationAccountSchema> getByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String integrationAccountName = Utils.getValueFromIdByName(id, "integrationAccounts");
        if (integrationAccountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'integrationAccounts'.", id)));
        }
        String schemaName = Utils.getValueFromIdByName(id, "schemas");
        if (schemaName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'schemas'.", id)));
        }
        return this.getWithResponse(resourceGroupName, integrationAccountName, schemaName, context);
    }

    public void deleteById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String integrationAccountName = Utils.getValueFromIdByName(id, "integrationAccounts");
        if (integrationAccountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'integrationAccounts'.", id)));
        }
        String schemaName = Utils.getValueFromIdByName(id, "schemas");
        if (schemaName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'schemas'.", id)));
        }
        this.deleteWithResponse(resourceGroupName, integrationAccountName, schemaName, Context.NONE);
    }

    public Response<Void> deleteByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String integrationAccountName = Utils.getValueFromIdByName(id, "integrationAccounts");
        if (integrationAccountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'integrationAccounts'.", id)));
        }
        String schemaName = Utils.getValueFromIdByName(id, "schemas");
        if (schemaName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'schemas'.", id)));
        }
        return this.deleteWithResponse(resourceGroupName, integrationAccountName, schemaName, context);
    }

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

    private com.azure.resourcemanager.logic.LogicManager manager() {
        return this.serviceManager;
    }

    public IntegrationAccountSchemaImpl define(String name) {
        return new IntegrationAccountSchemaImpl(name, this.manager());
    }
}
