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 settings = sequelize.define(
    'settings',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

company_name: {
        type: DataTypes.TEXT,
      
      

      },

legal_name: {
        type: DataTypes.TEXT,
      
      

      },

address: {
        type: DataTypes.TEXT,
      
      

      },

phone: {
        type: DataTypes.TEXT,
      
      

      },

email: {
        type: DataTypes.TEXT,
      
      

      },

city: {
        type: DataTypes.TEXT,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

tax_id: {
        type: DataTypes.TEXT,
      
      

      },

primary_color: {
        type: DataTypes.TEXT,
      
      

      },

secondary_color: {
        type: DataTypes.TEXT,
      
      

      },

theme: {
        type: DataTypes.ENUM,
      
      

        values: [

"light",


"dark",


"system"

        ],

      },

invoice_prefix: {
        type: DataTypes.TEXT,
      
      

      },

quote_prefix: {
        type: DataTypes.TEXT,
      
      

      },

sale_prefix: {
        type: DataTypes.TEXT,
      
      

      },

invoice_next_number: {
        type: DataTypes.INTEGER,
      
      

      },

quote_next_number: {
        type: DataTypes.INTEGER,
      
      

      },

sale_next_number: {
        type: DataTypes.INTEGER,
      
      

      },

invoice_footer_note: {
        type: DataTypes.TEXT,
      
      

      },

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

  settings.associate = (db) => {


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



























//end loop





    db.settings.hasMany(db.file, {
      as: 'logo',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.settings.getTableName(),
        belongsToColumn: 'logo',
      },
    });


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

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



  return settings;
};


