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

package com.azure.resourcemanager.automation.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.automation.fluent.models.HybridRunbookWorkerInner;
import com.azure.resourcemanager.automation.models.HybridRunbookWorker;
import com.azure.resourcemanager.automation.models.HybridRunbookWorkerCreateParameters;
import com.azure.resourcemanager.automation.models.HybridRunbookWorkerMoveParameters;
import com.azure.resourcemanager.automation.models.WorkerType;
import java.time.OffsetDateTime;

public final class HybridRunbookWorkerImpl implements HybridRunbookWorker, HybridRunbookWorker.Definition {
    private HybridRunbookWorkerInner innerObject;

    private final com.azure.resourcemanager.automation.AutomationManager serviceManager;

    HybridRunbookWorkerImpl(
        HybridRunbookWorkerInner innerObject, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

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

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

    public OffsetDateTime registeredDateTime() {
        return this.innerModel().registeredDateTime();
    }

    public OffsetDateTime lastSeenDateTime() {
        return this.innerModel().lastSeenDateTime();
    }

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

    public WorkerType workerType() {
        return this.innerModel().workerType();
    }

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

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

    private com.azure.resourcemanager.automation.AutomationManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String automationAccountName;

    private String hybridRunbookWorkerGroupName;

    private String hybridRunbookWorkerId;

    private HybridRunbookWorkerCreateParameters createHybridRunbookWorkerCreationParameters;

    public HybridRunbookWorkerImpl withExistingHybridRunbookWorkerGroup(
        String resourceGroupName, String automationAccountName, String hybridRunbookWorkerGroupName) {
        this.resourceGroupName = resourceGroupName;
        this.automationAccountName = automationAccountName;
        this.hybridRunbookWorkerGroupName = hybridRunbookWorkerGroupName;
        return this;
    }

    public HybridRunbookWorker create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHybridRunbookWorkers()
                .createWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    hybridRunbookWorkerGroupName,
                    hybridRunbookWorkerId,
                    createHybridRunbookWorkerCreationParameters,
                    Context.NONE)
                .getValue();
        return this;
    }

    public HybridRunbookWorker create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHybridRunbookWorkers()
                .createWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    hybridRunbookWorkerGroupName,
                    hybridRunbookWorkerId,
                    createHybridRunbookWorkerCreationParameters,
                    context)
                .getValue();
        return this;
    }

    HybridRunbookWorkerImpl(String name, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerObject = new HybridRunbookWorkerInner();
        this.serviceManager = serviceManager;
        this.hybridRunbookWorkerId = name;
        this.createHybridRunbookWorkerCreationParameters = new HybridRunbookWorkerCreateParameters();
    }

    public HybridRunbookWorker refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHybridRunbookWorkers()
                .getWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    hybridRunbookWorkerGroupName,
                    hybridRunbookWorkerId,
                    Context.NONE)
                .getValue();
        return this;
    }

    public HybridRunbookWorker refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getHybridRunbookWorkers()
                .getWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    hybridRunbookWorkerGroupName,
                    hybridRunbookWorkerId,
                    context)
                .getValue();
        return this;
    }

    public void move(HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters) {
        serviceManager
            .hybridRunbookWorkers()
            .move(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerMoveParameters);
    }

    public Response<Void> moveWithResponse(
        HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters, Context context) {
        return serviceManager
            .hybridRunbookWorkers()
            .moveWithResponse(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerMoveParameters,
                context);
    }

    public HybridRunbookWorkerImpl withName(String name) {
        this.createHybridRunbookWorkerCreationParameters.withName(name);
        return this;
    }

    public HybridRunbookWorkerImpl withVmResourceId(String vmResourceId) {
        this.createHybridRunbookWorkerCreationParameters.withVmResourceId(vmResourceId);
        return this;
    }
}
