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

package com.azure.resourcemanager.batchai.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.batchai.fluent.ExperimentsClient;
import com.azure.resourcemanager.batchai.fluent.models.ExperimentInner;
import com.azure.resourcemanager.batchai.models.Experiment;
import com.azure.resourcemanager.batchai.models.Experiments;
import com.fasterxml.jackson.annotation.JsonIgnore;

public final class ExperimentsImpl implements Experiments {
    @JsonIgnore private final ClientLogger logger = new ClientLogger(ExperimentsImpl.class);

    private final ExperimentsClient innerClient;

    private final com.azure.resourcemanager.batchai.BatchAIManager serviceManager;

    public ExperimentsImpl(
        ExperimentsClient innerClient, com.azure.resourcemanager.batchai.BatchAIManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<Experiment> listByWorkspace(String resourceGroupName, String workspaceName) {
        PagedIterable<ExperimentInner> inner = this.serviceClient().listByWorkspace(resourceGroupName, workspaceName);
        return Utils.mapPage(inner, inner1 -> new ExperimentImpl(inner1, this.manager()));
    }

    public PagedIterable<Experiment> listByWorkspace(
        String resourceGroupName, String workspaceName, Integer maxResults, Context context) {
        PagedIterable<ExperimentInner> inner =
            this.serviceClient().listByWorkspace(resourceGroupName, workspaceName, maxResults, context);
        return Utils.mapPage(inner, inner1 -> new ExperimentImpl(inner1, this.manager()));
    }

    public Experiment create(String resourceGroupName, String workspaceName, String experimentName) {
        ExperimentInner inner = this.serviceClient().create(resourceGroupName, workspaceName, experimentName);
        if (inner != null) {
            return new ExperimentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Experiment create(String resourceGroupName, String workspaceName, String experimentName, Context context) {
        ExperimentInner inner = this.serviceClient().create(resourceGroupName, workspaceName, experimentName, context);
        if (inner != null) {
            return new ExperimentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void delete(String resourceGroupName, String workspaceName, String experimentName) {
        this.serviceClient().delete(resourceGroupName, workspaceName, experimentName);
    }

    public void delete(String resourceGroupName, String workspaceName, String experimentName, Context context) {
        this.serviceClient().delete(resourceGroupName, workspaceName, experimentName, context);
    }

    public Experiment get(String resourceGroupName, String workspaceName, String experimentName) {
        ExperimentInner inner = this.serviceClient().get(resourceGroupName, workspaceName, experimentName);
        if (inner != null) {
            return new ExperimentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Experiment> getWithResponse(
        String resourceGroupName, String workspaceName, String experimentName, Context context) {
        Response<ExperimentInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, workspaceName, experimentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ExperimentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.batchai.BatchAIManager manager() {
        return this.serviceManager;
    }
}
