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

name: {
        type: DataTypes.TEXT,

      },

status: {
        type: DataTypes.TEXT,

      },

campaign_number: {
        type: DataTypes.TEXT,

      },

thyme_campaign_number: {
        type: DataTypes.TEXT,

      },

campaign_name: {
        type: DataTypes.TEXT,

      },

scheduled_completion_date: {
        type: DataTypes.DATE,

      },

billing_status: {
        type: DataTypes.TEXT,

      },

total_cost: {
        type: DataTypes.DECIMAL,

      },

total_invoiced: {
        type: DataTypes.DECIMAL,

      },

uninvoiced: {
        type: DataTypes.DECIMAL,

      },

remaining_invoice_decimal: {
        type: DataTypes.DECIMAL,

      },

timing_project_id: {
        type: DataTypes.TEXT,

      },

timing_app_department_id: {
        type: DataTypes.TEXT,

      },

timing_id: {
        type: DataTypes.TEXT,

      },

client_details: {
        type: DataTypes.TEXT,

      },

sub_brand: {
        type: DataTypes.TEXT,

      },

start_date: {
        type: DataTypes.DATE,

      },

admin_override: {
        type: DataTypes.BOOLEAN,

        allowNull: false,
        defaultValue: false,

      },

current_date: {
        type: DataTypes.DATE,

      },

contact_info: {
        type: DataTypes.TEXT,

      },

client_contact: {
        type: DataTypes.TEXT,

      },

country: {
        type: DataTypes.TEXT,

      },

language: {
        type: DataTypes.TEXT,

      },

client_ref: {
        type: DataTypes.TEXT,

      },

client_job_number: {
        type: DataTypes.TEXT,

      },

invoice_number: {
        type: DataTypes.TEXT,

      },

revenue_code: {
        type: DataTypes.TEXT,

      },

created_date: {
        type: DataTypes.DATE,

      },

last_updated_date: {
        type: DataTypes.DATE,

      },

timing_app: {
        type: DataTypes.TEXT,

      },

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

  campaigns.associate = (db) => {

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

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

  return campaigns;
};

