// 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.exception.ManagementError;
import com.azure.core.util.Context;
import com.azure.resourcemanager.automation.fluent.models.SoftwareUpdateConfigurationInner;
import com.azure.resourcemanager.automation.models.SoftwareUpdateConfiguration;
import com.azure.resourcemanager.automation.models.SoftwareUpdateConfigurationTasks;
import com.azure.resourcemanager.automation.models.SucScheduleProperties;
import com.azure.resourcemanager.automation.models.UpdateConfiguration;
import java.time.OffsetDateTime;

public final class SoftwareUpdateConfigurationImpl
    implements SoftwareUpdateConfiguration, SoftwareUpdateConfiguration.Definition {
    private SoftwareUpdateConfigurationInner innerObject;

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

    SoftwareUpdateConfigurationImpl(
        SoftwareUpdateConfigurationInner 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 UpdateConfiguration updateConfiguration() {
        return this.innerModel().updateConfiguration();
    }

    public SucScheduleProperties scheduleInfo() {
        return this.innerModel().scheduleInfo();
    }

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

    public ManagementError error() {
        return this.innerModel().error();
    }

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

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

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

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

    public SoftwareUpdateConfigurationTasks tasks() {
        return this.innerModel().tasks();
    }

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

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

    private String resourceGroupName;

    private String automationAccountName;

    private String softwareUpdateConfigurationName;

    private String createClientRequestId;

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

    public SoftwareUpdateConfiguration create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSoftwareUpdateConfigurations()
                .createWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    softwareUpdateConfigurationName,
                    this.innerModel(),
                    createClientRequestId,
                    Context.NONE)
                .getValue();
        return this;
    }

    public SoftwareUpdateConfiguration create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSoftwareUpdateConfigurations()
                .createWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    softwareUpdateConfigurationName,
                    this.innerModel(),
                    createClientRequestId,
                    context)
                .getValue();
        return this;
    }

    SoftwareUpdateConfigurationImpl(
        String name, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerObject = new SoftwareUpdateConfigurationInner();
        this.serviceManager = serviceManager;
        this.softwareUpdateConfigurationName = name;
        this.createClientRequestId = null;
    }

    public SoftwareUpdateConfiguration refresh() {
        String localClientRequestId = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSoftwareUpdateConfigurations()
                .getByNameWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    softwareUpdateConfigurationName,
                    localClientRequestId,
                    Context.NONE)
                .getValue();
        return this;
    }

    public SoftwareUpdateConfiguration refresh(Context context) {
        String localClientRequestId = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSoftwareUpdateConfigurations()
                .getByNameWithResponse(
                    resourceGroupName,
                    automationAccountName,
                    softwareUpdateConfigurationName,
                    localClientRequestId,
                    context)
                .getValue();
        return this;
    }

    public SoftwareUpdateConfigurationImpl withUpdateConfiguration(UpdateConfiguration updateConfiguration) {
        this.innerModel().withUpdateConfiguration(updateConfiguration);
        return this;
    }

    public SoftwareUpdateConfigurationImpl withScheduleInfo(SucScheduleProperties scheduleInfo) {
        this.innerModel().withScheduleInfo(scheduleInfo);
        return this;
    }

    public SoftwareUpdateConfigurationImpl withError(ManagementError error) {
        this.innerModel().withError(error);
        return this;
    }

    public SoftwareUpdateConfigurationImpl withTasks(SoftwareUpdateConfigurationTasks tasks) {
        this.innerModel().withTasks(tasks);
        return this;
    }

    public SoftwareUpdateConfigurationImpl withClientRequestId(String clientRequestId) {
        this.createClientRequestId = clientRequestId;
        return this;
    }
}
