'use strict';
const { defaultKeys, migrationDefaults, relationShip } = require('../sequelize/defaults');
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('collections', {
      ...defaultKeys("collection_id"),
      tbl_ref_id: {
        type: Sequelize.STRING,
        allowNull: true,
      },
      branch_id: relationShip({
        modelName: "branches",
        key: "branch_id",
        allowNull: false,
      }),
      area_id: relationShip({
        modelName: "areas",
        key: "area_id",
        allowNull: false,
      }),
      order_id: relationShip({
        modelName: "orders",
        key: "order_id",
        allowNull: false,
      }),
      collection_date: {
        type: Sequelize.DATEONLY,
        allowNull: false,
      },
      payment_type: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: 'collection',
      },
      payment_mode: {
        type: Sequelize.STRING,
        allowNull: true,
      },
      amount: {
        type: Sequelize.DECIMAL(10, 2),
        allowNull: false,
      },
      ...migrationDefaults(),
    });
  },
  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('collections');
  }
};