const { Sequelize, DataTypes } = require('sequelize');

const { DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD } = process.env;

const sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASSWORD, {
  host: DB_HOST,
  port: DB_PORT,
  dialect: 'mysql',
});

const Auth = sequelize.define(
  'Auths',
  {
    uid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
    username: { type: DataTypes.STRING, allowNull: false },
    password: { type: DataTypes.STRING, allowNull: false },
    session: { type: DataTypes.STRING, allowNull: false, defaultValue: '' },
    role: { type: DataTypes.STRING, allowNull: false },
  },
  { timestamps: false },
);

export { Auth, sequelize };
