import { BaseSchema } from '@adonisjs/lucid/schema'

export default class extends BaseSchema {
  protected tableName = 'organizations'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      // UUID v4 (cf. convention projet).
      table.uuid('id').primary().notNullable().defaultTo(this.raw('gen_random_uuid()'))
      table.string('name', 120).notNullable().defaultTo('')
      table.string('siret', 14).nullable()
      table.string('monthly_volume_bucket', 20).nullable()
      table.integer('rubis_count').notNullable().defaultTo(0)
      // Onboarding terminé = non-null. Tant que c'est null, le SPA renvoie
      // l'utilisateur dans le wizard (cf. docs/tech/backend.md §4.2).
      table.timestamp('onboarding_completed_at').nullable()

      table.timestamp('created_at').notNullable()
      table.timestamp('updated_at').nullable()
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
