import { QueryInterface, DataTypes } from 'sequelize';

module.exports = {
  up: async (queryInterface: QueryInterface) => {
    await queryInterface.createTable('work_note_attachments', {
      attachment_id: { type: DataTypes.UUID, primaryKey: true, defaultValue: DataTypes.UUIDV4, allowNull: false },
      note_id: { type: DataTypes.UUID, allowNull: false },
      file_name: { type: DataTypes.STRING(255), allowNull: false },
      file_type: { type: DataTypes.STRING(100), allowNull: false },
      file_size: { type: DataTypes.BIGINT, allowNull: false },
      file_path: { type: DataTypes.STRING(500), allowNull: false },
      storage_url: { type: DataTypes.STRING(500), allowNull: true },
      is_downloadable: { type: DataTypes.BOOLEAN, allowNull: true },
      download_count: { type: DataTypes.INTEGER, allowNull: true, defaultValue: 0 },
      uploaded_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW }
    });
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "work_note_attachments_note_id" ON "work_note_attachments" ("note_id");');
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "work_note_attachments_uploaded_at" ON "work_note_attachments" ("uploaded_at");');
  },
  down: async (queryInterface: QueryInterface) => {
    await queryInterface.dropTable('work_note_attachments');
  }
};


