package redfishprofile

func supermicroProfile() Profile {
	return staticProfile{
		name:            "supermicro",
		priority:        20,
		safeForFallback: true,
		matchFn: func(s MatchSignals) int {
			score := 0
			if containsFold(s.SystemManufacturer, "supermicro") || containsFold(s.ChassisManufacturer, "supermicro") {
				score += 80
			}
			for _, hint := range s.ResourceHints {
				if containsFold(hint, "hgx_baseboard") || containsFold(hint, "hgx_gpu_sxm") {
					score += 20
					break
				}
			}
			return min(score, 100)
		},
		extendAcquisition: func(plan *AcquisitionPlan, _ MatchSignals) {
			ensureSnapshotMaxDocuments(plan, 150000)
			ensureSnapshotWorkers(plan, 6)
			ensurePrefetchWorkers(plan, 4)
			ensureETABaseline(plan, AcquisitionETABaseline{
				DiscoverySeconds:     15,
				SnapshotSeconds:      180,
				PrefetchSeconds:      35,
				CriticalPlanBSeconds: 45,
				ProfilePlanBSeconds:  30,
			})
			ensurePostProbePolicy(plan, AcquisitionPostProbePolicy{
				EnableDirectNVMEDiskBayProbe: true,
			})
			ensureRecoveryPolicy(plan, AcquisitionRecoveryPolicy{
				EnableProfilePlanB: true,
			})
			ensureRatePolicy(plan, AcquisitionRatePolicy{
				TargetP95LatencyMS:      1200,
				ThrottleP95LatencyMS:    2400,
				MinSnapshotWorkers:      2,
				MinPrefetchWorkers:      1,
				DisablePrefetchOnErrors: true,
			})
			addPlanNote(plan, "supermicro acquisition extensions enabled")
		},
		refineAcquisition: func(resolved *ResolvedAcquisitionPlan, _ DiscoveredResources, signals MatchSignals) {
			for _, hint := range signals.ResourceHints {
				if normalizePath(hint) != "/redfish/v1/UpdateService/Oem/Supermicro/FirmwareInventory" {
					continue
				}
				addPlanPaths(&resolved.CriticalPaths, hint)
				addPlanPaths(&resolved.Plan.CriticalPaths, hint)
				addPlanPaths(&resolved.Plan.PlanBPaths, hint)
				break
			}
		},
		applyAnalysisDirectives: func(d *AnalysisDirectives, _ MatchSignals) {
			d.EnableStorageEnclosureRecovery = true
		},
		refineAnalysis: func(plan *ResolvedAnalysisPlan, snapshot map[string]interface{}, _ DiscoveredResources, _ MatchSignals) {
			if snapshotHasPathContaining(snapshot, "/chassis/nvmessd.") && snapshotHasPathContaining(snapshot, ".storagebackplane") {
				plan.Directives.EnableSupermicroNVMeBackplane = true
				addAnalysisNote(plan, "supermicro analysis enables NVMe backplane recovery from snapshot paths")
			}
			if snapshotHasStorageControllerHint(snapshot, "/storage/intelvroc", "/storage/ha-raid", "/storage/mrvl.ha-raid") {
				plan.Directives.EnableKnownStorageControllerRecovery = true
				addAnalysisStorageDriveCollections(plan,
					"/Storage/IntelVROC/Drives",
					"/Storage/IntelVROC/Controllers/1/Drives",
				)
				addAnalysisStorageVolumeCollections(plan,
					"/Storage/IntelVROC/Volumes",
					"/Storage/HA-RAID/Volumes",
					"/Storage/MRVL.HA-RAID/Volumes",
				)
				addAnalysisNote(plan, "supermicro analysis enables known storage-controller recovery from snapshot paths")
			}
		},
	}
}
