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

package com.azure.resourcemanager.networkcloud.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.networkcloud.fluent.models.BareMetalMachineInner;
import com.azure.resourcemanager.networkcloud.models.AdministrativeCredentials;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachine;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineCordonParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineCordonStatus;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineDetailedStatus;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachinePatchParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachinePowerOffParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachinePowerState;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineProvisioningState;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineReadyState;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineReplaceParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineRunCommandParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineRunDataExtractsParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineRunReadCommandsParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineValidateHardwareParameters;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import com.azure.resourcemanager.networkcloud.models.HardwareInventory;
import com.azure.resourcemanager.networkcloud.models.HardwareValidationStatus;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class BareMetalMachineImpl
    implements BareMetalMachine, BareMetalMachine.Definition, BareMetalMachine.Update {
    private BareMetalMachineInner innerObject;

    private final com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager;

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

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

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

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

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

    public ExtendedLocation extendedLocation() {
        return this.innerModel().extendedLocation();
    }

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

    public List<String> associatedResourceIds() {
        List<String> inner = this.innerModel().associatedResourceIds();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

    public AdministrativeCredentials bmcCredentials() {
        return this.innerModel().bmcCredentials();
    }

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

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

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

    public BareMetalMachineCordonStatus cordonStatus() {
        return this.innerModel().cordonStatus();
    }

    public BareMetalMachineDetailedStatus detailedStatus() {
        return this.innerModel().detailedStatus();
    }

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

    public HardwareInventory hardwareInventory() {
        return this.innerModel().hardwareInventory();
    }

    public HardwareValidationStatus hardwareValidationStatus() {
        return this.innerModel().hardwareValidationStatus();
    }

    public List<String> hybridAksClustersAssociatedIds() {
        List<String> inner = this.innerModel().hybridAksClustersAssociatedIds();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

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

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

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

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

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

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

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

    public BareMetalMachinePowerState powerState() {
        return this.innerModel().powerState();
    }

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

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

    public long rackSlot() {
        return this.innerModel().rackSlot();
    }

    public BareMetalMachineReadyState readyState() {
        return this.innerModel().readyState();
    }

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

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

    public List<String> virtualMachinesAssociatedIds() {
        List<String> inner = this.innerModel().virtualMachinesAssociatedIds();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.networkcloud.NetworkCloudManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String bareMetalMachineName;

    private BareMetalMachinePatchParameters updateBareMetalMachineUpdateParameters;

    public BareMetalMachineImpl withExistingResourceGroup(String resourceGroupName) {
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public BareMetalMachine create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBareMetalMachines()
                .createOrUpdate(resourceGroupName, bareMetalMachineName, this.innerModel(), Context.NONE);
        return this;
    }

    public BareMetalMachine create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBareMetalMachines()
                .createOrUpdate(resourceGroupName, bareMetalMachineName, this.innerModel(), context);
        return this;
    }

    BareMetalMachineImpl(String name, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = new BareMetalMachineInner();
        this.serviceManager = serviceManager;
        this.bareMetalMachineName = name;
    }

    public BareMetalMachineImpl update() {
        this.updateBareMetalMachineUpdateParameters = new BareMetalMachinePatchParameters();
        return this;
    }

    public BareMetalMachine apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBareMetalMachines()
                .update(resourceGroupName, bareMetalMachineName, updateBareMetalMachineUpdateParameters, Context.NONE);
        return this;
    }

    public BareMetalMachine apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBareMetalMachines()
                .update(resourceGroupName, bareMetalMachineName, updateBareMetalMachineUpdateParameters, context);
        return this;
    }

    BareMetalMachineImpl(
        BareMetalMachineInner innerObject, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.bareMetalMachineName = Utils.getValueFromIdByName(innerObject.id(), "bareMetalMachines");
    }

    public BareMetalMachine refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBareMetalMachines()
                .getByResourceGroupWithResponse(resourceGroupName, bareMetalMachineName, Context.NONE)
                .getValue();
        return this;
    }

    public BareMetalMachine refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBareMetalMachines()
                .getByResourceGroupWithResponse(resourceGroupName, bareMetalMachineName, context)
                .getValue();
        return this;
    }

    public void cordon() {
        serviceManager.bareMetalMachines().cordon(resourceGroupName, bareMetalMachineName);
    }

    public void cordon(BareMetalMachineCordonParameters bareMetalMachineCordonParameters, Context context) {
        serviceManager
            .bareMetalMachines()
            .cordon(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters, context);
    }

    public void powerOff() {
        serviceManager.bareMetalMachines().powerOff(resourceGroupName, bareMetalMachineName);
    }

    public void powerOff(BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters, Context context) {
        serviceManager
            .bareMetalMachines()
            .powerOff(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters, context);
    }

    public void reimage() {
        serviceManager.bareMetalMachines().reimage(resourceGroupName, bareMetalMachineName);
    }

    public void reimage(Context context) {
        serviceManager.bareMetalMachines().reimage(resourceGroupName, bareMetalMachineName, context);
    }

    public void replace() {
        serviceManager.bareMetalMachines().replace(resourceGroupName, bareMetalMachineName);
    }

    public void replace(BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters, Context context) {
        serviceManager
            .bareMetalMachines()
            .replace(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters, context);
    }

    public void restart() {
        serviceManager.bareMetalMachines().restart(resourceGroupName, bareMetalMachineName);
    }

    public void restart(Context context) {
        serviceManager.bareMetalMachines().restart(resourceGroupName, bareMetalMachineName, context);
    }

    public void runCommand(BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters) {
        serviceManager
            .bareMetalMachines()
            .runCommand(resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters);
    }

    public void runCommand(BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters, Context context) {
        serviceManager
            .bareMetalMachines()
            .runCommand(resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters, context);
    }

    public void runDataExtracts(BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters) {
        serviceManager
            .bareMetalMachines()
            .runDataExtracts(resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters);
    }

    public void runDataExtracts(
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters, Context context) {
        serviceManager
            .bareMetalMachines()
            .runDataExtracts(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters, context);
    }

    public void runReadCommands(BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters) {
        serviceManager
            .bareMetalMachines()
            .runReadCommands(resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters);
    }

    public void runReadCommands(
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters, Context context) {
        serviceManager
            .bareMetalMachines()
            .runReadCommands(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters, context);
    }

    public void start() {
        serviceManager.bareMetalMachines().start(resourceGroupName, bareMetalMachineName);
    }

    public void start(Context context) {
        serviceManager.bareMetalMachines().start(resourceGroupName, bareMetalMachineName, context);
    }

    public void uncordon() {
        serviceManager.bareMetalMachines().uncordon(resourceGroupName, bareMetalMachineName);
    }

    public void uncordon(Context context) {
        serviceManager.bareMetalMachines().uncordon(resourceGroupName, bareMetalMachineName, context);
    }

    public void validateHardware(
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters) {
        serviceManager
            .bareMetalMachines()
            .validateHardware(resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters);
    }

    public void validateHardware(
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters, Context context) {
        serviceManager
            .bareMetalMachines()
            .validateHardware(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters, context);
    }

    public BareMetalMachineImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

    public BareMetalMachineImpl withRegion(String location) {
        this.innerModel().withLocation(location);
        return this;
    }

    public BareMetalMachineImpl withExtendedLocation(ExtendedLocation extendedLocation) {
        this.innerModel().withExtendedLocation(extendedLocation);
        return this;
    }

    public BareMetalMachineImpl withBmcConnectionString(String bmcConnectionString) {
        this.innerModel().withBmcConnectionString(bmcConnectionString);
        return this;
    }

    public BareMetalMachineImpl withBmcCredentials(AdministrativeCredentials bmcCredentials) {
        this.innerModel().withBmcCredentials(bmcCredentials);
        return this;
    }

    public BareMetalMachineImpl withBmcMacAddress(String bmcMacAddress) {
        this.innerModel().withBmcMacAddress(bmcMacAddress);
        return this;
    }

    public BareMetalMachineImpl withBootMacAddress(String bootMacAddress) {
        this.innerModel().withBootMacAddress(bootMacAddress);
        return this;
    }

    public BareMetalMachineImpl withMachineDetails(String machineDetails) {
        if (isInCreateMode()) {
            this.innerModel().withMachineDetails(machineDetails);
            return this;
        } else {
            this.updateBareMetalMachineUpdateParameters.withMachineDetails(machineDetails);
            return this;
        }
    }

    public BareMetalMachineImpl withMachineName(String machineName) {
        this.innerModel().withMachineName(machineName);
        return this;
    }

    public BareMetalMachineImpl withMachineSkuId(String machineSkuId) {
        this.innerModel().withMachineSkuId(machineSkuId);
        return this;
    }

    public BareMetalMachineImpl withRackId(String rackId) {
        this.innerModel().withRackId(rackId);
        return this;
    }

    public BareMetalMachineImpl withRackSlot(long rackSlot) {
        this.innerModel().withRackSlot(rackSlot);
        return this;
    }

    public BareMetalMachineImpl withSerialNumber(String serialNumber) {
        this.innerModel().withSerialNumber(serialNumber);
        return this;
    }

    public BareMetalMachineImpl withTags(Map<String, String> tags) {
        if (isInCreateMode()) {
            this.innerModel().withTags(tags);
            return this;
        } else {
            this.updateBareMetalMachineUpdateParameters.withTags(tags);
            return this;
        }
    }

    private boolean isInCreateMode() {
        return this.innerModel().id() == null;
    }
}
