package regras

import (
	"testing"
)

func TestClausulaInOuTodosAtivos(t *testing.T) {
	if got := ClausulaInOuTodosAtivos(nil); got != "" {
		t.Fatalf("esperado vazio, got %q", got)
	}
	got := ClausulaInOuTodosAtivos([]int{1, 2, 2, 0})
	want := " AND id_imovel IN (1,2)"
	if got != want {
		t.Fatalf("got %q want %q", got, want)
	}
}

func TestMontarClausulaSendAll(t *testing.T) {
	r := MontarClausulaELimiteExportacao(ParametrosExportacao{
		StatusConfig: 1,
		SendAll:      1,
		IDsMarcados:  []int{10, 20},
	})
	if r.ClausulaExtra != "" {
		t.Fatalf("send_all=1 deve ignorar IN, got %q", r.ClausulaExtra)
	}
}

func TestMontarClausulaStatusZero(t *testing.T) {
	r := MontarClausulaELimiteExportacao(ParametrosExportacao{StatusConfig: 0})
	if r.Limit != " LIMIT 0 " {
		t.Fatalf("status 0 => LIMIT 0, got %q", r.Limit)
	}
}

func TestMontarClausulaChaveNaMaoSendAll(t *testing.T) {
	r := MontarClausulaChaveNaMao(ParametrosExportacao{
		StatusConfig: 1,
		SendAll:      1,
		IDsMarcados:  []int{10, 20},
	}, false)
	if r.ClausulaExtra != " AND id_imovel IN (10,20)" {
		t.Fatalf("ChaveNaMao send_all=1 mantém IN, got %q", r.ClausulaExtra)
	}
}

func TestMontarClausulaChaveNaMaoLimit(t *testing.T) {
	r := MontarClausulaChaveNaMao(ParametrosExportacao{
		StatusConfig: 1,
		LimiteXML:    50,
		IDsMarcados:  []int{1},
	}, true)
	if r.Limit != " LIMIT 50 " {
		t.Fatalf("limit: %q", r.Limit)
	}
	if r.OrderBy == "" {
		t.Fatal("order by esperado com limite chavenamao")
	}
}

func TestTipoTransacaoVivareal(t *testing.T) {
	if TipoTransacaoVivareal("Venda") != "For Sale" {
		t.Fatal("venda")
	}
	if TipoTransacaoVivareal("Locação") != "For Rent" {
		t.Fatal("locacao")
	}
}
