const { DataTypes } = require('sequelize')

module.exports = (sequelize) => {
  const KycSubmission = sequelize.define(
    'KycSubmission',
    {
      id: {
        type: DataTypes.BIGINT.UNSIGNED,
        autoIncrement: true,
        primaryKey: true,
      },
      userId: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: false,
      },
      step: {
        type: DataTypes.ENUM(
          'basic_info',
          'phone',
          'id_document',
          'selfie',
          'address_proof',
          'source_of_funds',
          'enhanced_due_diligence'
        ),
        allowNull: false,
      },
      status: {
        type: DataTypes.ENUM(
          'not_started',
          'pending',
          'approved',
          'rejected',
          'resubmitted',
          'expired'
        ),
        allowNull: false,
        defaultValue: 'pending',
      },
      submittedAt: {
        type: DataTypes.DATE,
        allowNull: true,
      },
      reviewedAt: {
        type: DataTypes.DATE,
        allowNull: true,
      },
      reviewedBy: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: true,
      },
      reviewNote: {
        type: DataTypes.TEXT,
        allowNull: true,
      },
      metadata: {
        type: DataTypes.JSON,
        allowNull: true,
      },
    },
    {
      tableName: 'kyc_submissions',
      timestamps: true,
      indexes: [
        { fields: ['userId'] },
        { fields: ['step'] },
        { fields: ['status'] },
        { unique: true, fields: ['userId', 'step'] },
      ],
    }
  );

 
  return KycSubmission;
};