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

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

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')
      table
        .integer('delivery_agent_id')
        .unsigned()
        .references('id')
        .inTable('users')
        .onDelete('CASCADE')
        .notNullable()
      table
        .integer('order_id')
        .unsigned()
        .references('id')
        .inTable('orders')
        .onDelete('CASCADE')
        .nullable()
      table.tinyint('transaction_type').notNullable() // remittance or payment collection
      table.tinyint('payment_method').notNullable() // cash, benefit
      table.decimal('amount', 12, 3).notNullable()
      table.decimal('balance', 12, 3).notNullable()
      table.dateTime('transaction_date').notNullable()

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

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