const { DataTypes } = require('sequelize')

module.exports = (sequelize) => {
  const KycDocument = sequelize.define(
    'KycDocument',
    {
      id: {
        type: DataTypes.BIGINT.UNSIGNED,
        autoIncrement: true,
        primaryKey: true,
      },
      userId: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: false,
      },
      submissionId: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: false,
      },
      verificationType: {
        type: DataTypes.ENUM('identity', 'selfie', 'address', 'enhanced'),
        allowNull: false,
      },
      documentType: {
        type: DataTypes.STRING(100),
        allowNull: false,
      },
      fileUrl: {
        type: DataTypes.STRING(2048),
        allowNull: false,
      },
      fileName: {
        type: DataTypes.STRING(255),
        allowNull: true,
      },
      mimeType: {
        type: DataTypes.STRING(100),
        allowNull: true,
      },
      fileSize: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: true,
      },
      status: {
        type: DataTypes.ENUM(
          'pending',
          'approved',
          'rejected',
          'resubmitted',
          'expired'
        ),
        allowNull: false,
        defaultValue: 'pending',
      },
      reviewNote: {
        type: DataTypes.TEXT,
        allowNull: true,
      },
      reviewedBy: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: true,
      },
      reviewedAt: {
        type: DataTypes.DATE,
        allowNull: true,
      },
      submittedAt: {
        type: DataTypes.DATE,
        allowNull: true,
      },
      metadata: {
        type: DataTypes.JSON,
        allowNull: true,
      },
    },
    {
      tableName: 'kyc_documents',
      timestamps: true,
      indexes: [
        { fields: ['userId'] },
        { fields: ['submissionId'] },
        { fields: ['verificationType'] },
        { fields: ['status'] },
      ],
    }
  );


  return KycDocument;
};