const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const tax_periods = sequelize.define(
    'tax_periods',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

period_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"monthly",


"quarterly",


"annual"

        ],

      },

year_number: {
        type: DataTypes.INTEGER,
      
      

      },

period_number: {
        type: DataTypes.INTEGER,
      
      

      },

start_date: {
        type: DataTypes.DATE,
      
      

      },

end_date: {
        type: DataTypes.DATE,
      
      

      },

due_date: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"in_review",


"ready_to_file",


"filed",


"amended",


"closed"

        ],

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  tax_periods.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity



















    db.tax_periods.hasMany(db.vat_declarations, {
      as: 'vat_declarations_tax_period',
      foreignKey: {
          name: 'tax_periodId',
      },
      constraints: false,
    });


    db.tax_periods.hasMany(db.tot_declarations, {
      as: 'tot_declarations_tax_period',
      foreignKey: {
          name: 'tax_periodId',
      },
      constraints: false,
    });


    db.tax_periods.hasMany(db.declaration_submissions, {
      as: 'declaration_submissions_tax_period',
      foreignKey: {
          name: 'tax_periodId',
      },
      constraints: false,
    });





//end loop



    db.tax_periods.belongsTo(db.merchants, {
      as: 'merchant',
      foreignKey: {
        name: 'merchantId',
      },
      constraints: false,
    });

    db.tax_periods.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




    db.tax_periods.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.tax_periods.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return tax_periods;
};


