import std/os
import ../../../query_builder/models/baradb/baradb_types
import ../../models/table
import ../../enums
import ../sub/migration_table_def
import ./create_query_def
import ../../queries/baradb/create_migration_table
import ../../queries/baradb/reset_table
import ../../queries/baradb/create_table

proc create*(rdb: BaradbConnections, tables: varargs[Table]) =
  let cmd = commandLineParams()
  let isReset = defined(reset) or cmd.contains("--reset")
  var query = createSchema(rdb, migrationTable)
  query.createMigrationTable()
  if isReset:
    for i in countdown(tables.len-1, 0):
      let table = tables[i]
      query = createSchema(rdb, table)
      query.resetTable()
  for table in tables:
    table.usecaseType = Create
    query = createSchema(rdb, table)
    query.createTable(isReset)
