package prisma

import (
	"strings"
	"testing"

	"git.warky.dev/wdevs/relspecgo/pkg/models"
	"git.warky.dev/wdevs/relspecgo/pkg/writers"
)

func TestGenerateGenerator_DefaultsToPrismaClientJS(t *testing.T) {
	t.Parallel()

	writer := NewWriter(&writers.WriterOptions{})
	db := models.InitDatabase("testdb")

	got := writer.generateGenerator(db)
	if !strings.Contains(got, `provider = "prisma-client-js"`) {
		t.Fatalf("expected prisma-client-js generator, got:\n%s", got)
	}
	if strings.Contains(got, `output   = "./generated"`) {
		t.Fatalf("did not expect prisma7 output path in default generator:\n%s", got)
	}
}

func TestGenerateGenerator_Prisma7FlagUsesPrismaClient(t *testing.T) {
	t.Parallel()

	writer := NewWriter(&writers.WriterOptions{Prisma7: true})
	db := models.InitDatabase("testdb")

	got := writer.generateGenerator(db)
	if !strings.Contains(got, `provider = "prisma-client"`) {
		t.Fatalf("expected prisma-client generator, got:\n%s", got)
	}
	if !strings.Contains(got, `output   = "./generated"`) {
		t.Fatalf("expected prisma7 output path, got:\n%s", got)
	}
}

func TestGenerateGenerator_Prisma7SourceFormatUsesPrismaClient(t *testing.T) {
	t.Parallel()

	writer := NewWriter(&writers.WriterOptions{})
	db := models.InitDatabase("testdb")
	db.SourceFormat = "prisma7"

	got := writer.generateGenerator(db)
	if !strings.Contains(got, `provider = "prisma-client"`) {
		t.Fatalf("expected prisma-client generator from source format, got:\n%s", got)
	}
}
