import {
    Sequelize,
    DataTypes,
    Model,
    InferAttributes,
    InferCreationAttributes,
    CreationOptional,
    sql,
    BelongsToGetAssociationMixin,
    Association,
    NonAttribute,
  } from '@sequelize/core';

import { User } from "./User";


import { SqliteDialect } from '@sequelize/sqlite3';
import { Attribute, AutoIncrement, BelongsTo, Default, NotNull, PrimaryKey, Table, Unique } from "@sequelize/core/decorators-legacy";

@Table({
    tableName: 'Auths'
})
export class Auth extends Model<InferAttributes<Auth>, InferCreationAttributes<Auth>> {

    @Attribute(DataTypes.INTEGER)
    @PrimaryKey
    @AutoIncrement
    @Unique
    declare id: CreationOptional<number>;

    @Attribute(DataTypes.UUIDV4)
    @Default(sql.uuidV4)
    declare token: CreationOptional<string>;

    @Attribute(DataTypes.INTEGER)
    @NotNull
    declare user_id:number;

    @BelongsTo( ()=>User, { foreignKey: 'user_id', inverse: { type: 'hasMany', as: 'authtokens' } } )
    declare user?: NonAttribute<User>


    declare getUser: BelongsToGetAssociationMixin<User>;
    declare static associations: {
        user: Association<User, Auth>;
    };
}

