package service

import (
	"os"
	"testing"
)

func TestIsProductionEnv_StageIsProductionLike(t *testing.T) {
	t.Setenv("APP_ENV", "stage")
	t.Setenv("GO_ENV", "")

	if !IsProductionEnv() {
		t.Fatalf("expected stage to be treated as production-like")
	}
}

func TestIsDryRunAllowed_DisabledInStage(t *testing.T) {
	t.Setenv("APP_ENV", "stage")
	t.Setenv("GO_ENV", "")

	if IsDryRunAllowed() {
		t.Fatalf("expected dry-run to be disabled in stage")
	}
}

func TestIsProductionEnv_FallsBackToGoEnv(t *testing.T) {
	originalAppEnv, hadAppEnv := os.LookupEnv("APP_ENV")
	if hadAppEnv {
		t.Cleanup(func() {
			_ = os.Setenv("APP_ENV", originalAppEnv)
		})
	} else {
		t.Cleanup(func() {
			_ = os.Unsetenv("APP_ENV")
		})
	}
	_ = os.Unsetenv("APP_ENV")
	t.Setenv("GO_ENV", "production")

	if !IsProductionEnv() {
		t.Fatalf("expected GO_ENV=production fallback to be production-like")
	}
}
