const { DataTypes } = require("sequelize");
const sequelize = require("../config/database");

const ImageMetadata = sequelize.define(
  "ImageMetadata",
  {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    s3Key: {
      type: DataTypes.TEXT,
      allowNull: false,
      unique: true,
    },
    latitude: {
      type: DataTypes.DECIMAL(10, 8),
      allowNull: true,
    },
    longitude: {
      type: DataTypes.DECIMAL(11, 8),
      allowNull: true,
    },
    cameraMake: {
      type: DataTypes.STRING(100),
      allowNull: true,
    },
    cameraModel: {
      type: DataTypes.STRING(100),
      allowNull: true,
    },
    cameraSoftware: {
      type: DataTypes.STRING(100),
      allowNull: true,
    },
    dateTaken: {
      type: DataTypes.DATE,
      allowNull: true,
    },
    width: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    height: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    orientation: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    fileSize: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    processingStatus: {
      type: DataTypes.ENUM("pending", "processing", "completed", "failed"),
      allowNull: false,
      defaultValue: "pending",
    },
    processedAt: {
      type: DataTypes.DATE,
      allowNull: true,
    },
    errorMessage: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
  },
  {
    timestamps: true,
    indexes: [
      {
        fields: ["s3Key"],
        unique: true,
      },
      {
        fields: ["latitude", "longitude"],
      },
      {
        fields: ["processingStatus"],
      },
    ],
  }
);

module.exports = ImageMetadata;
