package user

import (
	"context"

	log "github.com/sirupsen/logrus"
)

func resourceUserUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
	log.Debug("resourceUserUpgradeV1: upgrading state from list to string")

	if oldVal, ok := rawState["emailaddress"].([]interface{}); ok && len(oldVal) > 0 {
		if firstEmail, ok := oldVal[0].(string); ok {
			rawState["emailaddress"] = firstEmail
			log.Debugf("resourceUserUpgradeV1: converted emailaddress from list to string: %s", firstEmail)
		}
	}

	return rawState, nil
}
