'use strict';
const { defaultKeys, migrationDefaults, relationShip } = require('../sequelize/defaults');
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('orders', {
      ...defaultKeys("order_id"),
      tbl_ref_id: {
        type: Sequelize.STRING,
        allowNull: true,
      },
      branch_id: relationShip({
        modelName: "branches",
        key: "branch_id",
        allowNull: false,
      }),
      collection_day: {
        type: Sequelize.ENUM(["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]),
        allowNull: false,
      },
      order_date: {
        type: Sequelize.DATEONLY,
        allowNull: false,
      },
      order_no: {
        type: Sequelize.STRING,
        allowNull: false,
      },
      customer_id: relationShip({
        modelName: "customers",
        key: "customer_id",
        allowNull: false,
      }),
      area_id: relationShip({
        modelName: "areas",
        key: "area_id",
        allowNull: false,
      }),
      landmark_id: relationShip({
        modelName: "landmarks",
        key: "landmark_id",
        allowNull: false,
      }),
      sub_amount: {
        type: Sequelize.DECIMAL(10, 2),
        allowNull: false,
      },
      advance_amount: {
        type: Sequelize.DECIMAL(10, 2),
        allowNull: true,
      },
      total_amount: {
        type: Sequelize.DECIMAL(10, 2),
        allowNull: false,
      },
      payment_status: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: 'Unpaid',
      },
      ...migrationDefaults({ isUser: true }),
    });
  },
  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('orders');
  }
};