// 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.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.automation.fluent.models.DscCompilationJobInner;
import com.azure.resourcemanager.automation.models.DscCompilationJob;
import com.azure.resourcemanager.automation.models.DscCompilationJobCreateParameters;
import com.azure.resourcemanager.automation.models.DscConfigurationAssociationProperty;
import com.azure.resourcemanager.automation.models.JobProvisioningState;
import com.azure.resourcemanager.automation.models.JobStatus;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;

public final class DscCompilationJobImpl implements DscCompilationJob, DscCompilationJob.Definition {
    private DscCompilationJobInner innerObject;

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

    DscCompilationJobImpl(
        DscCompilationJobInner 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 DscConfigurationAssociationProperty configuration() {
        return this.innerModel().configuration();
    }

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

    public UUID jobId() {
        return this.innerModel().jobId();
    }

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

    public JobProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

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

    public JobStatus status() {
        return this.innerModel().status();
    }

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

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

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

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

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

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

    public Map<String, String> parameters() {
        Map<String, String> inner = this.innerModel().parameters();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

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

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

    private String resourceGroupName;

    private String automationAccountName;

    private String compilationJobName;

    private DscCompilationJobCreateParameters createParameters;

    public DscCompilationJobImpl withExistingAutomationAccount(String resourceGroupName, String automationAccountName) {
        this.resourceGroupName = resourceGroupName;
        this.automationAccountName = automationAccountName;
        return this;
    }

    public DscCompilationJob create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDscCompilationJobs()
                .create(resourceGroupName, automationAccountName, compilationJobName, createParameters, Context.NONE);
        return this;
    }

    public DscCompilationJob create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDscCompilationJobs()
                .create(resourceGroupName, automationAccountName, compilationJobName, createParameters, context);
        return this;
    }

    DscCompilationJobImpl(String name, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerObject = new DscCompilationJobInner();
        this.serviceManager = serviceManager;
        this.compilationJobName = name;
        this.createParameters = new DscCompilationJobCreateParameters();
    }

    public DscCompilationJob refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDscCompilationJobs()
                .getWithResponse(resourceGroupName, automationAccountName, compilationJobName, Context.NONE)
                .getValue();
        return this;
    }

    public DscCompilationJob refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDscCompilationJobs()
                .getWithResponse(resourceGroupName, automationAccountName, compilationJobName, context)
                .getValue();
        return this;
    }

    public DscCompilationJobImpl withConfiguration(DscConfigurationAssociationProperty configuration) {
        this.createParameters.withConfiguration(configuration);
        return this;
    }

    public DscCompilationJobImpl withRegion(Region location) {
        this.createParameters.withLocation(location.toString());
        return this;
    }

    public DscCompilationJobImpl withRegion(String location) {
        this.createParameters.withLocation(location);
        return this;
    }

    public DscCompilationJobImpl withTags(Map<String, String> tags) {
        this.createParameters.withTags(tags);
        return this;
    }

    public DscCompilationJobImpl withName(String name) {
        this.createParameters.withName(name);
        return this;
    }

    public DscCompilationJobImpl withParameters(Map<String, String> parameters) {
        this.createParameters.withParameters(parameters);
        return this;
    }

    public DscCompilationJobImpl withIncrementNodeConfigurationBuild(Boolean incrementNodeConfigurationBuild) {
        this.createParameters.withIncrementNodeConfigurationBuild(incrementNodeConfigurationBuild);
        return this;
    }
}
