// Quick check if parent user exists in DB
import mysql from "mysql2/promise"

const pool = mysql.createPool({
  uri: "mysql://root:wx1998WX@mysql.eazygame.cn:14013/next_edu",
})

async function main() {
  const conn = await pool.getConnection()
  try {
    // Check parent user
    const [rows] = await conn.execute(
      "SELECT id, name, email, password FROM users WHERE email = ?",
      ["parent_g1c1_1@xiaoxue.edu.cn"],
    )
    console.log("Parent user:", JSON.stringify(rows, null, 2))

    // Check parent_student_relations
    const [cols] = await conn.execute("SHOW COLUMNS FROM parent_student_relations")
    console.log("\nparent_student_relations columns:", JSON.stringify(cols, null, 2))

    // Check relations using correct column names
    const [relations] = await conn.execute(
      `SELECT * FROM parent_student_relations WHERE parent_id = ?`,
      ["user_p_s_g1c1_1"],
    )
    console.log("\nParent relations:", JSON.stringify(relations, null, 2))

    // Check password_security
    const [sec] = await conn.execute(
      "SELECT * FROM password_security WHERE user_id = ?",
      ["user_p_s_g1c1_1"],
    )
    console.log("\nPassword security:", JSON.stringify(sec, null, 2))

    // Check roles
    const [roles] = await conn.execute(
      `SELECT r.name FROM users_to_roles utr JOIN roles r ON r.id = utr.role_id WHERE utr.user_id = ?`,
      ["user_p_s_g1c1_1"],
    )
    console.log("\nRoles:", JSON.stringify(roles, null, 2))
  } finally {
    conn.release()
    await pool.end()
  }
}

main().catch((e) => {
  console.error("Error:", e.message)
  process.exit(1)
})
