package rg

import (
	"context"

	log "github.com/sirupsen/logrus"
)

func resourceRGStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
	log.Debug("resourceRGStateUpgradeV1: upgrading state")
	quota, ok := rawState["quota"]
	if !ok || quota == nil {
		rawState["quota"] = QuotaRecord{
			Cpu:      -1,
			Ram:      -1,
			Disk:     -1,
			ExtIPs:   -1,
			GpuUnits: -1,
		}
		return rawState, nil
	}

	oldQuotaList := quota.([]interface{})
	oldQuota := oldQuotaList[0].(map[string]interface{})
	oldQuota["ram"] = int64(oldQuota["ram"].(float64))
	return rawState, nil
}
