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

package com.azure.resourcemanager.videoanalyzer.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.videoanalyzer.fluent.VideoAnalyzersClient;
import com.azure.resourcemanager.videoanalyzer.fluent.models.VideoAnalyzerCollectionInner;
import com.azure.resourcemanager.videoanalyzer.fluent.models.VideoAnalyzerInner;
import com.azure.resourcemanager.videoanalyzer.models.VideoAnalyzer;
import com.azure.resourcemanager.videoanalyzer.models.VideoAnalyzerCollection;
import com.azure.resourcemanager.videoanalyzer.models.VideoAnalyzers;

public final class VideoAnalyzersImpl implements VideoAnalyzers {
    private static final ClientLogger LOGGER = new ClientLogger(VideoAnalyzersImpl.class);

    private final VideoAnalyzersClient innerClient;

    private final com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager serviceManager;

    public VideoAnalyzersImpl(
        VideoAnalyzersClient innerClient, com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public VideoAnalyzerCollection list(String resourceGroupName) {
        VideoAnalyzerCollectionInner inner = this.serviceClient().list(resourceGroupName);
        if (inner != null) {
            return new VideoAnalyzerCollectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<VideoAnalyzerCollection> listWithResponse(String resourceGroupName, Context context) {
        Response<VideoAnalyzerCollectionInner> inner =
            this.serviceClient().listWithResponse(resourceGroupName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new VideoAnalyzerCollectionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public VideoAnalyzer getByResourceGroup(String resourceGroupName, String accountName) {
        VideoAnalyzerInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, accountName);
        if (inner != null) {
            return new VideoAnalyzerImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<VideoAnalyzer> getByResourceGroupWithResponse(
        String resourceGroupName, String accountName, Context context) {
        Response<VideoAnalyzerInner> inner =
            this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, accountName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new VideoAnalyzerImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public void deleteByResourceGroup(String resourceGroupName, String accountName) {
        this.serviceClient().delete(resourceGroupName, accountName);
    }

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

    public VideoAnalyzerCollection listBySubscription() {
        VideoAnalyzerCollectionInner inner = this.serviceClient().listBySubscription();
        if (inner != null) {
            return new VideoAnalyzerCollectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<VideoAnalyzerCollection> listBySubscriptionWithResponse(Context context) {
        Response<VideoAnalyzerCollectionInner> inner = this.serviceClient().listBySubscriptionWithResponse(context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new VideoAnalyzerCollectionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public VideoAnalyzer 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 accountName = Utils.getValueFromIdByName(id, "videoAnalyzers");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'videoAnalyzers'.", id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, accountName, Context.NONE).getValue();
    }

    public Response<VideoAnalyzer> 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 accountName = Utils.getValueFromIdByName(id, "videoAnalyzers");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'videoAnalyzers'.", id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, accountName, 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 accountName = Utils.getValueFromIdByName(id, "videoAnalyzers");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'videoAnalyzers'.", id)));
        }
        this.deleteWithResponse(resourceGroupName, accountName, 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 accountName = Utils.getValueFromIdByName(id, "videoAnalyzers");
        if (accountName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'videoAnalyzers'.", id)));
        }
        return this.deleteWithResponse(resourceGroupName, accountName, context);
    }

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

    private com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager manager() {
        return this.serviceManager;
    }

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