// Shared BU team constants and validation
// Used by user management routes, auth middleware, and frontend-facing endpoints.

const KNOWN_TEAMS = ['STEAM', 'ACCESS-ENG', 'ACCESS-OPS', 'INTELDEV'];

/**
 * Parse and validate a comma-separated teams string.
 * @param {string} teamsString - Comma-separated team identifiers (e.g. 'STEAM,ACCESS-ENG')
 * @returns {{ valid: boolean, teams: string[], invalid: string[] }}
 */
function validateTeams(teamsString) {
    if (!teamsString || typeof teamsString !== 'string' || teamsString.trim() === '') {
        return { valid: true, teams: [], invalid: [] };
    }

    const teams = teamsString.split(',').map(t => t.trim()).filter(Boolean);
    const invalid = teams.filter(t => !KNOWN_TEAMS.includes(t));

    return {
        valid: invalid.length === 0,
        teams,
        invalid
    };
}

module.exports = { KNOWN_TEAMS, validateTeams };
