import {
    Association,
    CreationOptional,
    DataTypes,
    ForeignKey,
    InferAttributes,
    InferCreationAttributes,
    Model,
    NonAttribute
} from "@sequelize/core";

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

import { Bucket } from "./Bucket";
type AttachmentAttributes = InferAttributes<Attachment>;
type AttachmentCreationAttributes = InferCreationAttributes<Attachment>;

export class Attachment extends Model<AttachmentAttributes,AttachmentCreationAttributes> {

    @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>;
    };

}
