package mysql

import (
	"reflect"
	"strings"
	"testing"

	roomservice "hyapp/services/room-service/internal/room/service"
)

func TestSplitHumanRobotAllowedOwnerIDs(t *testing.T) {
	shortIDs, userIDs := splitHumanRobotAllowedOwnerIDs([]string{" 1001 ", "abc", "1001", "1e3", "-2", ""})
	if !reflect.DeepEqual(shortIDs, []string{"1001", "abc", "1e3", "-2"}) {
		t.Fatalf("short ids mismatch: got %+v", shortIDs)
	}
	if !reflect.DeepEqual(userIDs, []int64{1001}) {
		t.Fatalf("owner user ids mismatch: got %+v", userIDs)
	}
}

func TestAdminRoomPinListSQLUsesSingleFromClause(t *testing.T) {
	where, _ := adminRoomPinWhere(t.Context(), roomservice.AdminRoomPinQuery{Status: "active", PinType: "region", NowMS: 1000})
	query := adminRoomPinSelectSQL() + where
	if count := strings.Count(query, "FROM room_region_pins"); count != 1 {
		t.Fatalf("room pin list SQL must contain one FROM clause, got %d in %q", count, query)
	}
}
