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

package com.azure.resourcemanager.devtestlabs.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.devtestlabs.fluent.SchedulesClient;
import com.azure.resourcemanager.devtestlabs.fluent.models.ScheduleInner;
import com.azure.resourcemanager.devtestlabs.models.Schedule;
import com.azure.resourcemanager.devtestlabs.models.ScheduleFragment;
import com.azure.resourcemanager.devtestlabs.models.Schedules;

public final class SchedulesImpl implements Schedules {
    private static final ClientLogger LOGGER = new ClientLogger(SchedulesImpl.class);

    private final SchedulesClient innerClient;

    private final com.azure.resourcemanager.devtestlabs.DevTestLabsManager serviceManager;

    public SchedulesImpl(
        SchedulesClient innerClient, com.azure.resourcemanager.devtestlabs.DevTestLabsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<Schedule> list(String resourceGroupName, String labName) {
        PagedIterable<ScheduleInner> inner = this.serviceClient().list(resourceGroupName, labName);
        return Utils.mapPage(inner, inner1 -> new ScheduleImpl(inner1, this.manager()));
    }

    public PagedIterable<Schedule> list(
        String resourceGroupName,
        String labName,
        String expand,
        String filter,
        Integer top,
        String orderby,
        Context context) {
        PagedIterable<ScheduleInner> inner =
            this.serviceClient().list(resourceGroupName, labName, expand, filter, top, orderby, context);
        return Utils.mapPage(inner, inner1 -> new ScheduleImpl(inner1, this.manager()));
    }

    public Response<Schedule> getWithResponse(
        String resourceGroupName, String labName, String name, String expand, Context context) {
        Response<ScheduleInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, labName, name, expand, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ScheduleImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Schedule get(String resourceGroupName, String labName, String name) {
        ScheduleInner inner = this.serviceClient().get(resourceGroupName, labName, name);
        if (inner != null) {
            return new ScheduleImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Schedule> createOrUpdateWithResponse(
        String resourceGroupName, String labName, String name, ScheduleInner schedule, Context context) {
        Response<ScheduleInner> inner =
            this.serviceClient().createOrUpdateWithResponse(resourceGroupName, labName, name, schedule, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ScheduleImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Schedule createOrUpdate(String resourceGroupName, String labName, String name, ScheduleInner schedule) {
        ScheduleInner inner = this.serviceClient().createOrUpdate(resourceGroupName, labName, name, schedule);
        if (inner != null) {
            return new ScheduleImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public void delete(String resourceGroupName, String labName, String name) {
        this.serviceClient().delete(resourceGroupName, labName, name);
    }

    public Response<Schedule> updateWithResponse(
        String resourceGroupName, String labName, String name, ScheduleFragment schedule, Context context) {
        Response<ScheduleInner> inner =
            this.serviceClient().updateWithResponse(resourceGroupName, labName, name, schedule, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ScheduleImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Schedule update(String resourceGroupName, String labName, String name, ScheduleFragment schedule) {
        ScheduleInner inner = this.serviceClient().update(resourceGroupName, labName, name, schedule);
        if (inner != null) {
            return new ScheduleImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void execute(String resourceGroupName, String labName, String name) {
        this.serviceClient().execute(resourceGroupName, labName, name);
    }

    public void execute(String resourceGroupName, String labName, String name, Context context) {
        this.serviceClient().execute(resourceGroupName, labName, name, context);
    }

    public PagedIterable<Schedule> listApplicable(String resourceGroupName, String labName, String name) {
        PagedIterable<ScheduleInner> inner = this.serviceClient().listApplicable(resourceGroupName, labName, name);
        return Utils.mapPage(inner, inner1 -> new ScheduleImpl(inner1, this.manager()));
    }

    public PagedIterable<Schedule> listApplicable(
        String resourceGroupName, String labName, String name, Context context) {
        PagedIterable<ScheduleInner> inner =
            this.serviceClient().listApplicable(resourceGroupName, labName, name, context);
        return Utils.mapPage(inner, inner1 -> new ScheduleImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.devtestlabs.DevTestLabsManager manager() {
        return this.serviceManager;
    }
}
