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

artifact_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"apk",


"aab",


"zip",


"log",


"report",


"preview_url"

        ],

      },

file_name: {
        type: DataTypes.TEXT,
      
      

      },

download_url: {
        type: DataTypes.TEXT,
      
      

      },

checksum_sha256: {
        type: DataTypes.TEXT,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

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

  build_artifacts.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.build_artifacts.belongsTo(db.build_jobs, {
      as: 'build_job',
      foreignKey: {
        name: 'build_jobId',
      },
      constraints: false,
    });

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



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


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

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



  return build_artifacts;
};


