/**
 * Reset repair data — clears all repair tickets, batches, templates, notes, and line items.
 * Run: bun run db:seed-reset-repairs
 *
 * Use this before switching between seed presets (e.g. generic → music store).
 */
import postgres from 'postgres'

const DB_URL = process.env.DATABASE_URL ?? 'postgresql://lunarfront:lunarfront@localhost:5432/lunarfront'
const sql = postgres(DB_URL)

async function reset() {
  console.log('Resetting repair data...')

  const notes = await sql`DELETE FROM repair_note RETURNING id`
  console.log(`  Deleted ${notes.length} notes`)

  const lineItems = await sql`DELETE FROM repair_line_item RETURNING id`
  console.log(`  Deleted ${lineItems.length} line items`)

  const tickets = await sql`DELETE FROM repair_ticket RETURNING id`
  console.log(`  Deleted ${tickets.length} tickets`)

  const batches = await sql`DELETE FROM repair_batch RETURNING id`
  console.log(`  Deleted ${batches.length} batches`)

  const templates = await sql`DELETE FROM repair_service_template RETURNING id`
  console.log(`  Deleted ${templates.length} templates`)

  console.log('\nRepair data cleared. Run a seed to repopulate.')
  await sql.end()
}

reset().catch((err) => {
  console.error('Reset failed:', err)
  process.exit(1)
})
