import { Association, BelongsToGetAssociationMixin, BelongsToManyGetAssociationsMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
import { Post } from "./Post";

import { SqliteDialect } from '@sequelize/sqlite3';
import { Attribute, AutoIncrement, BelongsTo, BelongsToMany, NotNull, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
import { Bucket } from "./Bucket";
import { UUID } from "crypto";

export class Attachment extends Model<InferAttributes<Attachment>, InferCreationAttributes<Attachment>> {
    @PrimaryKey
    @AutoIncrement
    @Attribute(DataTypes.INTEGER)
    @Unique
    declare id: CreationOptional<number>;
    @Attribute(DataTypes.STRING)
    declare filename: string
    
    // Associations
    @Attribute(DataTypes.UUIDV4)
    @NotNull
    declare bucket_id: ForeignKey<Bucket['id']>;

    @BelongsTo(()=>Bucket,{foreignKey: 'bucket_id', inverse: {type: "hasMany", as: 'attachments'}})
    declare bucket?:NonAttribute<Bucket>;

    declare static associations: {
        bucket: Association<Bucket, Attachment>;
    };
    
}
