// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
	"fmt"
	"strings"

	"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type VulnerabilityAssessmentVmId struct {
	SubscriptionId                    string
	ResourceGroup                     string
	VirtualMachineName                string
	ServerVulnerabilityAssessmentName string
}

func NewVulnerabilityAssessmentVmID(subscriptionId, resourceGroup, virtualMachineName, serverVulnerabilityAssessmentName string) VulnerabilityAssessmentVmId {
	return VulnerabilityAssessmentVmId{
		SubscriptionId:                    subscriptionId,
		ResourceGroup:                     resourceGroup,
		VirtualMachineName:                virtualMachineName,
		ServerVulnerabilityAssessmentName: serverVulnerabilityAssessmentName,
	}
}

func (id VulnerabilityAssessmentVmId) String() string {
	segments := []string{
		fmt.Sprintf("Server Vulnerability Assessment Name %q", id.ServerVulnerabilityAssessmentName),
		fmt.Sprintf("Virtual Machine Name %q", id.VirtualMachineName),
		fmt.Sprintf("Resource Group %q", id.ResourceGroup),
	}
	segmentsStr := strings.Join(segments, " / ")
	return fmt.Sprintf("%s: (%s)", "Vulnerability Assessment Vm", segmentsStr)
}

func (id VulnerabilityAssessmentVmId) ID() string {
	fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s/providers/Microsoft.Security/serverVulnerabilityAssessments/%s"
	return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.VirtualMachineName, id.ServerVulnerabilityAssessmentName)
}

// VulnerabilityAssessmentVmID parses a VulnerabilityAssessmentVm ID into an VulnerabilityAssessmentVmId struct
func VulnerabilityAssessmentVmID(input string) (*VulnerabilityAssessmentVmId, error) {
	id, err := resourceids.ParseAzureResourceID(input)
	if err != nil {
		return nil, fmt.Errorf("parsing %q as an VulnerabilityAssessmentVm ID: %+v", input, err)
	}

	resourceId := VulnerabilityAssessmentVmId{
		SubscriptionId: id.SubscriptionID,
		ResourceGroup:  id.ResourceGroup,
	}

	if resourceId.SubscriptionId == "" {
		return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
	}

	if resourceId.ResourceGroup == "" {
		return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
	}

	if resourceId.VirtualMachineName, err = id.PopSegment("virtualMachines"); err != nil {
		return nil, err
	}
	if resourceId.ServerVulnerabilityAssessmentName, err = id.PopSegment("serverVulnerabilityAssessments"); err != nil {
		return nil, err
	}

	if err := id.ValidateNoEmptySegments(input); err != nil {
		return nil, err
	}

	return &resourceId, nil
}
