import * as Sequelize from 'sequelize'

async function up (utils: {
  transaction: Sequelize.Transaction
  queryInterface: Sequelize.QueryInterface
  sequelize: Sequelize.Sequelize
}): Promise<void> {
  const query = `
    CREATE TABLE IF NOT EXISTS "eventRegistration" (
      "id" SERIAL PRIMARY KEY,
      "eventId" INTEGER NOT NULL REFERENCES "event" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
      "firstName" VARCHAR(255) NOT NULL,
      "lastName" VARCHAR(255) NOT NULL,
      "email" VARCHAR(320) NOT NULL,
      "phone" VARCHAR(50) NOT NULL,
      "companyName" VARCHAR(255) NOT NULL,
      "jobTitle" VARCHAR(255) NOT NULL,
      "country" VARCHAR(100) NOT NULL,
      "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
      "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
    )
  `

  await utils.sequelize.query(query, { transaction: utils.transaction })

  await utils.sequelize.query(
    `CREATE INDEX "idx_event_registration_eventId" ON "eventRegistration" ("eventId")`,
    { transaction: utils.transaction }
  )
}

function down (options) {
  throw new Error('Not implemented.')
}

export {
  up,
  down
}
