import { Model, DataTypes, InferAttributes, InferCreationAttributes } from 'sequelize';
import { sequelize } from './persistence/database';
import { Role } from './role.model';

export class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
    declare email: string;
    declare password: string;
    declare username: string;
    declare role: Role;
}

User.init(
    {
        email: {
            type: DataTypes.STRING,
            primaryKey: true,
            allowNull: false
        },
        password: {
            type: DataTypes.STRING,
            allowNull: false
        },
        username: {
            type: DataTypes.STRING,
            allowNull: false
        },
        role: {
            type: DataTypes.ENUM,
            values: Object.values(Role),
            allowNull: false
        }
    },
    {
        sequelize
        // Other model options go here
    },
    );