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

export interface PostTagAttributes extends Optional<PostTagInterface, 'id'> { }

export class PostTag extends Model<PostTagInterface, PostTagAttributes> implements PostTagInterface {
    public id!: number;
    public categoryId!: number;
    public postId!: number;

    static initModel(sequelize: Sequelize): typeof PostTag {
        PostTag.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                categoryId: { type: DataTypes.BIGINT, allowNull: false, comment: "ref to User" },
                postId: { type: DataTypes.BIGINT, allowNull: false, comment: "user referral" }
            },
            {
                paranoid: false,
                underscored: true,
                sequelize,
                tableName: 'post_tags',
                timestamps: true,
            }
        );
        return PostTag;
    }

    public static associate(models: any) {
        PostTag.belongsTo(models.Category, { foreignKey: 'categoryId' });
        PostTag.belongsTo(models.Post, { foreignKey: 'postId' });
    }
}
