"use strict";

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable("ImageMetadata", {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        primaryKey: true,
      },
      s3Key: {
        type: Sequelize.TEXT,
        allowNull: false,
        unique: true,
      },
      latitude: {
        type: Sequelize.DECIMAL(10, 8),
        allowNull: true,
      },
      longitude: {
        type: Sequelize.DECIMAL(11, 8),
        allowNull: true,
      },
      cameraMake: {
        type: Sequelize.STRING(100),
        allowNull: true,
      },
      cameraModel: {
        type: Sequelize.STRING(100),
        allowNull: true,
      },
      cameraSoftware: {
        type: Sequelize.STRING(100),
        allowNull: true,
      },
      dateTaken: {
        type: Sequelize.DATE,
        allowNull: true,
      },
      width: {
        type: Sequelize.INTEGER,
        allowNull: true,
      },
      height: {
        type: Sequelize.INTEGER,
        allowNull: true,
      },
      orientation: {
        type: Sequelize.INTEGER,
        allowNull: true,
      },
      fileSize: {
        type: Sequelize.INTEGER,
        allowNull: true,
      },
      processingStatus: {
        type: Sequelize.ENUM("pending", "processing", "completed", "failed"),
        allowNull: false,
        defaultValue: "pending",
      },
      processedAt: {
        type: Sequelize.DATE,
        allowNull: true,
      },
      errorMessage: {
        type: Sequelize.TEXT,
        allowNull: true,
      },
      createdAt: {
        type: Sequelize.DATE,
        allowNull: false,
      },
      updatedAt: {
        type: Sequelize.DATE,
        allowNull: false,
      },
    });

    // Add indexes
    await queryInterface.addIndex("ImageMetadata", ["s3Key"], {
      unique: true,
      name: "image_metadata_s3_key_unique",
    });
    await queryInterface.addIndex("ImageMetadata", ["latitude", "longitude"], {
      name: "image_metadata_geo",
    });
    await queryInterface.addIndex("ImageMetadata", ["processingStatus"], {
      name: "image_metadata_processing_status",
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable("ImageMetadata");
  },
};
