// 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.WorkflowTriggersClient;
import com.azure.resourcemanager.logic.fluent.models.JsonSchemaInner;
import com.azure.resourcemanager.logic.fluent.models.WorkflowTriggerCallbackUrlInner;
import com.azure.resourcemanager.logic.fluent.models.WorkflowTriggerInner;
import com.azure.resourcemanager.logic.models.JsonSchema;
import com.azure.resourcemanager.logic.models.SetTriggerStateActionDefinition;
import com.azure.resourcemanager.logic.models.WorkflowTrigger;
import com.azure.resourcemanager.logic.models.WorkflowTriggerCallbackUrl;
import com.azure.resourcemanager.logic.models.WorkflowTriggers;

public final class WorkflowTriggersImpl implements WorkflowTriggers {
    private static final ClientLogger LOGGER = new ClientLogger(WorkflowTriggersImpl.class);

    private final WorkflowTriggersClient innerClient;

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

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

    public PagedIterable<WorkflowTrigger> list(String resourceGroupName, String workflowName) {
        PagedIterable<WorkflowTriggerInner> inner = this.serviceClient().list(resourceGroupName, workflowName);
        return Utils.mapPage(inner, inner1 -> new WorkflowTriggerImpl(inner1, this.manager()));
    }

    public PagedIterable<WorkflowTrigger> list(
        String resourceGroupName, String workflowName, Integer top, String filter, Context context) {
        PagedIterable<WorkflowTriggerInner> inner =
            this.serviceClient().list(resourceGroupName, workflowName, top, filter, context);
        return Utils.mapPage(inner, inner1 -> new WorkflowTriggerImpl(inner1, this.manager()));
    }

    public Response<WorkflowTrigger> getWithResponse(
        String resourceGroupName, String workflowName, String triggerName, Context context) {
        Response<WorkflowTriggerInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, workflowName, triggerName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new WorkflowTriggerImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public WorkflowTrigger get(String resourceGroupName, String workflowName, String triggerName) {
        WorkflowTriggerInner inner = this.serviceClient().get(resourceGroupName, workflowName, triggerName);
        if (inner != null) {
            return new WorkflowTriggerImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> resetWithResponse(
        String resourceGroupName, String workflowName, String triggerName, Context context) {
        return this.serviceClient().resetWithResponse(resourceGroupName, workflowName, triggerName, context);
    }

    public void reset(String resourceGroupName, String workflowName, String triggerName) {
        this.serviceClient().reset(resourceGroupName, workflowName, triggerName);
    }

    public Response<Void> runWithResponse(
        String resourceGroupName, String workflowName, String triggerName, Context context) {
        return this.serviceClient().runWithResponse(resourceGroupName, workflowName, triggerName, context);
    }

    public void run(String resourceGroupName, String workflowName, String triggerName) {
        this.serviceClient().run(resourceGroupName, workflowName, triggerName);
    }

    public Response<JsonSchema> getSchemaJsonWithResponse(
        String resourceGroupName, String workflowName, String triggerName, Context context) {
        Response<JsonSchemaInner> inner =
            this.serviceClient().getSchemaJsonWithResponse(resourceGroupName, workflowName, triggerName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new JsonSchemaImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public JsonSchema getSchemaJson(String resourceGroupName, String workflowName, String triggerName) {
        JsonSchemaInner inner = this.serviceClient().getSchemaJson(resourceGroupName, workflowName, triggerName);
        if (inner != null) {
            return new JsonSchemaImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> setStateWithResponse(
        String resourceGroupName,
        String workflowName,
        String triggerName,
        SetTriggerStateActionDefinition setState,
        Context context) {
        return this
            .serviceClient()
            .setStateWithResponse(resourceGroupName, workflowName, triggerName, setState, context);
    }

    public void setState(
        String resourceGroupName, String workflowName, String triggerName, SetTriggerStateActionDefinition setState) {
        this.serviceClient().setState(resourceGroupName, workflowName, triggerName, setState);
    }

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

    public WorkflowTriggerCallbackUrl listCallbackUrl(
        String resourceGroupName, String workflowName, String triggerName) {
        WorkflowTriggerCallbackUrlInner inner =
            this.serviceClient().listCallbackUrl(resourceGroupName, workflowName, triggerName);
        if (inner != null) {
            return new WorkflowTriggerCallbackUrlImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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