import { DataTypes, Model, Optional, Sequelize } from 'sequelize';

export interface SessionAttributes extends Optional<SessionInterface, 'id'> { }

export class Session extends Model<SessionInterface, SessionAttributes> implements SessionInterface {
    public id!: number;
    public userId!: number;
    public accountId!: number | null;
    public token!: Text;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof Session {
        Session.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                userId: { type: DataTypes.BIGINT, allowNull: true, defaultValue: null, comment: "user's identifier" },
                accountId: { type: DataTypes.BIGINT, allowNull: true, defaultValue: null, comment: "user's identifier" },
                token: { type: DataTypes.TEXT, allowNull: false, comment: "session_token" },
            },
            { paranoid: true, underscored: true, sequelize, tableName: 'session', timestamps: true }
        );
        return Session;
    }

    public static associate(models: any) {

    }
}
