import { CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
import { User } from "./User";
import { Attribute, AutoIncrement, BelongsTo, CreatedAt, PrimaryKey, Table, Unique, UpdatedAt } from "@sequelize/core/decorators-legacy";
@Table({
    tableName: "Perms"
})
export class UserPerms extends Model<InferAttributes<UserPerms>, InferCreationAttributes<UserPerms>> {
    @Attribute(DataTypes.INTEGER)
    @PrimaryKey
    @AutoIncrement
    @Unique
    declare id: CreationOptional<number>;
    @BelongsTo(()=>User, { foreignKey: 'user_id', inverse: { as: 'perms', type: 'hasOne' } })
    declare user:NonAttribute<User>;
    @Attribute(DataTypes.INTEGER)
    declare user_id:ForeignKey<User['id']>;
    @Attribute(DataTypes.BOOLEAN)
    declare isAdmin:CreationOptional<boolean>;
    @CreatedAt
    declare createdAt: CreationOptional<Date>;
    @UpdatedAt
    declare updatedAt: CreationOptional<Date>;

}

export function addUserPermsScopes(){

UserPerms.addScope('defaultScope',{
    attributes: {
        exclude: ['createdAt', 'updatedAt'],
    }
});
UserPerms.addScope('withTimestamps',{
    attributes: {
        include: ['createdAt', 'updatedAt'],
    }
});
}

