const Sequelize = require("sequelize");
const sequelizeConnect = require("../connection/db");

const QrLoginSession = sequelizeConnect.define(
  "qr_login_sessions",
  {
    id: {
      type: Sequelize.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
    },
    user_id: {
      type: Sequelize.BIGINT,
      allowNull: true,
    },
    qr_token: {
      type: Sequelize.STRING(255),
      allowNull: false,
      unique: true,
    },
    status: {
      type: Sequelize.ENUM("pending", "authenticated"),
      allowNull: false,
      defaultValue: "pending",
    },
    ip_address: {
      type: Sequelize.STRING(45),
      allowNull: true,
    },
    user_agent: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    created_at: {
      type: Sequelize.DATE,
      allowNull: false,
      defaultValue: Sequelize.NOW,
    },
    scanned_at: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    authenticated_at: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    expires_at: {
      type: Sequelize.DATE,
      allowNull: false,
    },
  },
  {
    tableName: "qr_login_sessions",
    timestamps: false,
  }
);

module.exports = QrLoginSession;
