import { Model, DataTypes, InferAttributes, InferCreationAttributes, CreationOptional, ForeignKey, NonAttribute } from 'sequelize';
import { sequelize } from './persistence/database';
import { Category } from './category.model';

export class Event extends Model<InferAttributes<Event>, InferCreationAttributes<Event>> {
    declare id: CreationOptional<number>;
    declare title: string;
    declare description: string;
    declare emoji: string;
    declare categoryId: ForeignKey<Category>;
    declare category: NonAttribute<Category>;
    declare startDate: Date;
    declare endDate: Date;
}

Event.init(
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true,
        },
        title: {
            type: DataTypes.STRING,
            allowNull: false
        },
        description: {
            type: DataTypes.TEXT('long')
        },
        emoji: {
            type: DataTypes.STRING
        },
        startDate: {
            type: DataTypes.DATE,
            defaultValue: '1000-01-01 00:00:00',
            allowNull: false
        },
        endDate: {
            type: DataTypes.DATE,
            defaultValue: '1000-01-01 00:00:00',
            allowNull: false
        }
    },
    {
        sequelize
        // Other model options go here
    },
);


Category.hasMany(Event, {foreignKey: 'categoryId'});
Event.belongsTo(Category, {foreignKey: 'categoryId', as: 'category'});