package gateway

import (
	"slices"

	"realtime-gateway/internal/config"
	"realtime-gateway/internal/model"
)

func authorize(cfg config.AuthConfig, role model.Role, token string) bool {
	switch role {
	case model.RoleProducer:
		return slices.Contains(cfg.ProducerTokens, token)
	case model.RoleController:
		return slices.Contains(cfg.ControllerTokens, token)
	case model.RoleConsumer:
		if cfg.AllowAnonymousConsumers && token == "" {
			return true
		}
		return slices.Contains(cfg.ConsumerTokens, token)
	default:
		return false
	}
}
