import { DataTypes } from 'sequelize';
import sequelize from '../database.js';
import DiaryDate from './DiaryDates.js';
import PredefinedActivity from './PredefinedActivity.js';
import Group from './Group.js';

const DiaryDateActivity = sequelize.define('DiaryDateActivity', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    diaryDateId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
            model: DiaryDate,
            key: 'id',
        },
        onDelete: 'CASCADE',
    },
    isTimeblock: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false,
    },
    predefinedActivityId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
            model: PredefinedActivity,
            key: 'id',
        },
        onDelete: 'SET NULL',
    },
    groupId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
            model: Group,
            key: 'id'
        },
        onDelete: 'SET NULL'
    },
     duration: {
        type: DataTypes.INTEGER,
        allowNull: true,
    },
    durationText: {
        type: DataTypes.STRING,
        allowNull: true,
    },
    orderId: {
        type: DataTypes.INTEGER,
        allowNull: false,
    },
}, {
    tableName: 'diary_date_activities',
    underscored: true,
    timestamps: true,
});

export default DiaryDateActivity;
