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

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

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')
      table.integer('proforma_id').unsigned().references('id').inTable('proformas').onDelete('CASCADE')
      table.string('produto').notNullable()
      table.text('descricao').notNullable()
      table.integer('quantidade').notNullable()
      table.decimal('preco_unitario', 12, 2).notNullable()
      table.decimal('subtotal', 12, 2).notNullable()
      table.timestamp('created_at')
      table.timestamp('updated_at').nullable()
    })
  }

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