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

export interface UserSettingAttributes extends Optional<UserSettingInterface, 'id'> { }

export class UserSetting extends Model<UserSettingInterface, UserSettingAttributes> implements UserSettingInterface {
    public id!: number;
    public userId!: number;
    public twoFactorAuthentication!: boolean;
    public temporaryPassword!: boolean;
    public notificationCount!: number;
    public selectedTheme!: number;
    public profileQuestionnaireCompleted!: boolean;
    public profileDetailedQuestionnaireCompleted!: boolean;
    public interestSelected!: boolean;
    public isPremium!: boolean;
    public securityDeclaration!: boolean;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof UserSetting {
        UserSetting.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                userId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-account", comment: "User identifier" },
                twoFactorAuthentication: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: "Two factor auth enabled?" },
                temporaryPassword: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: "Is temporary password?" },
                notificationCount: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: "Account notification count?" },
                selectedTheme: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 1, comment: "Default theme specifier?" },
                profileQuestionnaireCompleted: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: "profiling questionnaire completed" },
                profileDetailedQuestionnaireCompleted: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: "profiling questionnaire completed" },
                interestSelected: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: "interests selection completed" },
                isPremium: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: "if premium user" },
                securityDeclaration: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: "" },
            },
            { paranoid: true, underscored: true, sequelize, tableName: 'user_setting', timestamps: true }
        );
        return UserSetting;
    }

    public static associate(models: any) {
        UserSetting.belongsTo(models.User, { foreignKey: 'userId' });
    }
}
