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

export interface PostAttachmentAttributes { }

export class PostAttachment extends Model<PostAttachmentInterface, PostAttachmentAttributes> implements PostAttachmentInterface {
    public postId!: number;
    public attachmentId!: number;
    public isFeatured!: boolean;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof PostAttachment {
        PostAttachment.init(
            {
                postId: { type: DataTypes.BIGINT, allowNull: false, comment: "post identifier", unique: 'post-attachment' },
                attachmentId: { type: DataTypes.BIGINT, allowNull: false, comment: "attachment identifier", unique: 'post-attachment' },
                isFeatured: { type: DataTypes.BOOLEAN, allowNull: true, defaultValue: false, comment: "is featured" },
            },
            {
                paranoid: false,
                underscored: true,
                sequelize,
                tableName: 'post_attachments',
                timestamps: true,
            }
        );
        return PostAttachment;
    }

    public static associate(models: any) {
        PostAttachment.belongsTo(models.Post, { foreignKey: 'postId' });
        PostAttachment.belongsTo(models.Attachment, { foreignKey: 'attachmentId' });
    }
}