package mysql

import (
	"testing"

	rulepkg "github.com/actiontech/sqle/sqle/driver/mysql/rule"
	"github.com/actiontech/sqle/sqle/driver/mysql/rule/ai"
	"github.com/actiontech/sqle/sqle/driver/mysql/session"
)

// ==== Rule test code start ====
func TestRuleSQLE00002(t *testing.T) {
	ruleName := ai.SQLE00002
	rule := rulepkg.AIRuleHandlerMap[ruleName].Rule

	// Case 1: DELETE statement with 100 placeholders in WHERE clause
	runAIRuleCase(rule, t, "case 1: DELETE statement with 100 placeholders in WHERE clause",
		"DELETE FROM user_table WHERE id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE user_table (id INT PRIMARY KEY, name VARCHAR(50));"),
		nil,
		newTestResult(),
	)

	// Case 2: DELETE statement with 101 placeholders in WHERE clause
	runAIRuleCase(rule, t, "case 2: DELETE statement with 101 placeholders in WHERE clause",
		"DELETE FROM user_table WHERE id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE user_table (id INT PRIMARY KEY, name VARCHAR(50));"),
		nil,
		newTestResult().addResult(ruleName),
	)

	// Case 3: INSERT statement with 100 placeholders in VALUES clause
	runAIRuleCase(rule, t, "case 3: INSERT statement with 100 placeholders in VALUES clause",
		"INSERT INTO order_table (product_id, quantity) VALUES (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE order_table (product_id INT, quantity INT);"),
		nil,
		newTestResult(),
	)

	// Case 4: INSERT statement with 101 placeholders in VALUES clause
	runAIRuleCase(rule, t, "case 4: INSERT statement with 101 placeholders in VALUES clause",
		"INSERT INTO order_table (product_id, quantity) VALUES (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE order_table (product_id INT, quantity INT);"),
		nil,
		newTestResult().addResult(ruleName),
	)

	// Case 5: SELECT statement with 100 placeholders in WHERE clause
	runAIRuleCase(rule, t, "case 5: SELECT statement with 100 placeholders in WHERE clause",
		"SELECT * FROM product_table WHERE category_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE product_table (category_id INT, product_name VARCHAR(100));"),
		nil,
		newTestResult(),
	)

	// Case 6: SELECT statement with 101 placeholders in WHERE clause
	runAIRuleCase(rule, t, "case 6: SELECT statement with 101 placeholders in WHERE clause",
		"SELECT * FROM product_table WHERE category_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE product_table (category_id INT, product_name VARCHAR(100));"),
		nil,
		newTestResult().addResult(ruleName),
	)

	// Case 7: UPDATE statement with 100 placeholders in SET and WHERE clauses
	runAIRuleCase(rule, t, "case 7: UPDATE statement with 100 placeholders in SET and WHERE clauses",
		"UPDATE inventory_table SET stock = ? WHERE product_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE inventory_table (product_id INT, stock INT);"),
		nil,
		newTestResult(),
	)

	// Case 8: UPDATE statement with 101 placeholders in SET and WHERE clauses
	runAIRuleCase(rule, t, "case 8: UPDATE statement with 101 placeholders in SET and WHERE clauses",
		"UPDATE inventory_table SET stock = ? WHERE product_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE inventory_table (product_id INT, stock INT);"),
		nil,
		newTestResult().addResult(ruleName),
	)

	// Case 9: SELECT UNION statement with 101 placeholders in WHERE clause
	runAIRuleCase(rule, t, "case 6: SELECT statement with 101 placeholders in WHERE clause",
		"select * from product_table union SELECT * FROM product_table WHERE category_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
		session.NewAIMockContext().WithSQL("CREATE TABLE product_table (category_id INT, product_name VARCHAR(100));"),
		nil,
		newTestResult().addResult(ruleName),
	)
}

// ==== Rule test code end ====
