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

package com.azure.resourcemanager.machinelearning.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.machinelearning.fluent.models.ScheduleInner;
import com.azure.resourcemanager.machinelearning.models.Schedule;
import com.azure.resourcemanager.machinelearning.models.ScheduleProperties;

public final class ScheduleImpl implements Schedule, Schedule.Definition, Schedule.Update {
    private ScheduleInner innerObject;

    private final com.azure.resourcemanager.machinelearning.MachineLearningManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public ScheduleProperties properties() {
        return this.innerModel().properties();
    }

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public ScheduleInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.machinelearning.MachineLearningManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String workspaceName;

    private String name;

    public ScheduleImpl withExistingWorkspace(String resourceGroupName, String workspaceName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        return this;
    }

    public Schedule create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSchedules()
                .createOrUpdate(resourceGroupName, workspaceName, name, this.innerModel(), Context.NONE);
        return this;
    }

    public Schedule create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSchedules()
                .createOrUpdate(resourceGroupName, workspaceName, name, this.innerModel(), context);
        return this;
    }

    ScheduleImpl(String name, com.azure.resourcemanager.machinelearning.MachineLearningManager serviceManager) {
        this.innerObject = new ScheduleInner();
        this.serviceManager = serviceManager;
        this.name = name;
    }

    public ScheduleImpl update() {
        return this;
    }

    public Schedule apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSchedules()
                .createOrUpdate(resourceGroupName, workspaceName, name, this.innerModel(), Context.NONE);
        return this;
    }

    public Schedule apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSchedules()
                .createOrUpdate(resourceGroupName, workspaceName, name, this.innerModel(), context);
        return this;
    }

    ScheduleImpl(
        ScheduleInner innerObject, com.azure.resourcemanager.machinelearning.MachineLearningManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.workspaceName = Utils.getValueFromIdByName(innerObject.id(), "workspaces");
        this.name = Utils.getValueFromIdByName(innerObject.id(), "schedules");
    }

    public Schedule refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSchedules()
                .getWithResponse(resourceGroupName, workspaceName, name, Context.NONE)
                .getValue();
        return this;
    }

    public Schedule refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSchedules()
                .getWithResponse(resourceGroupName, workspaceName, name, context)
                .getValue();
        return this;
    }

    public ScheduleImpl withProperties(ScheduleProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
