package utils

import (
	"bssapp-backend/auth"
	"bssapp-backend/models"
	"strconv"
	"strings"
)

func UserFromClaims(c *auth.Claims) *models.User {
	if c == nil {
		return nil
	}

	v3Group := 0
	if raw := strings.TrimSpace(c.V3UserGroup); raw != "" {
		if parsed, err := strconv.Atoi(raw); err == nil {
			v3Group = parsed
		}
	}

	return &models.User{
		ID:                  int(c.ID),
		Username:            c.Username,
		RoleID:              int(c.RoleID),
		RoleCode:            c.RoleCode,
		V3Username:          strings.TrimSpace(c.V3Username),
		V3UserGroup:         v3Group,
		ForcePasswordChange: c.ForcePasswordChange,
	}
}
