import { Sequelize, QueryInterface, QueryTypes, Op } from 'sequelize';
import * as Constants from "../src/api/config/constants"
interface universalIdentifier {
    id: number
}
const date = new Date()
export default {
    up: async (queryInterface: QueryInterface) => {
        let accounts = await queryInterface.sequelize.query(`select id from accounts where \`key\` in ('${process.env.DEFAULT_ACCOUNT_KEY}','default-key') limit 1`, { type: QueryTypes.SELECT }) as universalIdentifier[];
        if (accounts.length == 0) {
            const accountData = [
                {
                    code: process.env.DEFAULT_ACCOUNT_CODE || 'default-code',
                    name: process.env.DEFAULT_ACCOUNT_NAME || 'default-name',
                    key: process.env.DEFAULT_ACCOUNT_KEY || 'default-key',
                    status: Constants.ACCOUNT.STATUS.ACTIVE,
                    created_at: date,
                    updated_at: date
                }
            ];
            let accounts = await queryInterface.bulkInsert('accounts', accountData);
        } else {
            console.log("accounts already initialized")
        }
    },

    down: async (queryInterface: QueryInterface) => {
        await queryInterface.bulkDelete('accounts', { truncate: true, restartIdentity: true, cascade: true });
    },
};
