package httpapi

import (
	"errors"
	"testing"

	"github.com/easyai/easyai-ai-gateway/apps/api/internal/config"
)

func TestAdmittedTaskRunModeReservesAcceptanceAndProductionSimulation(t *testing.T) {
	server := &Server{cfg: config.Config{AppEnv: "production"}}
	for _, runMode := range []string{"simulation", "SIMULATION", "acceptance", "acceptance_canary"} {
		_, err := server.admittedTaskRunMode(taskTrafficAdmission{}, map[string]any{"runMode": runMode})
		var trafficErr *taskTrafficError
		if !errors.As(err, &trafficErr) || trafficErr.Status != 403 {
			t.Fatalf("run mode %q error=%v", runMode, err)
		}
	}
	for _, runMode := range []string{"acceptance", "acceptance_canary"} {
		got, err := server.admittedTaskRunMode(taskTrafficAdmission{RunMode: runMode}, map[string]any{
			"runMode": "production",
		})
		if err != nil || got != runMode {
			t.Fatalf("admitted mode=%q got=%q err=%v", runMode, got, err)
		}
	}
}
