const { DataTypes } = require('sequelize');


module.exports = (sequelize) => {
   const BotSubscription = sequelize.define('BotSubscription', {
  id: {
    type: DataTypes.BIGINT.UNSIGNED,
    autoIncrement:true,
    allowNull: false,
    primaryKey: true,
  },
  userId: {
    type: DataTypes.BIGINT.UNSIGNED,
    allowNull: false,
    field: 'user_id',
    references: {
      model: 'Users',
      key: 'id',
    },
  },
  botMarketplaceId: {
    type: DataTypes.BIGINT.UNSIGNED,
    allowNull: false,
    field: 'bot_marketplace_id',
    references: {
      model: 'BotMarketplace',
      key: 'id',
    },
  },
  status: {
    type: DataTypes.ENUM('active', 'cancelled','stopped','paused', 'expired', 'suspended'),
    defaultValue: 'active',
  },
  startDate: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    field: 'start_date',
  },
  endDate: {
    type: DataTypes.DATE,
    field: 'end_date',
  },
  autoRenew: {
    type: DataTypes.BOOLEAN,
    defaultValue: true,
    field: 'auto_renew',
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
  },
  pricePeriod: {
    type: DataTypes.ENUM('day','month', 'year', 'lifetime'),
    field: 'price_period',
    defaultValue: 'month',
  },
  lastPaymentDate: {
    type: DataTypes.DATE,
    field: 'last_payment_date'
  },
  nextPaymentDate: {
    type: DataTypes.DATE,
    field: 'next_payment_date'
  },
  rating: {
    type: DataTypes.INTEGER, // User's rating of the bot (1-5)
  },
  review: {
    type: DataTypes.TEXT,
  },
  reviewedAt: {
    type: DataTypes.DATE,
    field: 'reviewed_at'
  },
}, {
  tableName: "bot_subscriptions",
  timestamps: true,
  indexes: [
    { fields: ['userId'] },
    { fields: ['botMarketplaceId'] },
    { fields: ['status'] },
  ],
});
  return BotSubscription
}


