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

const Subscriptions = sequelize.define("Subscriptions", {
  subscriptionEndsAt: {
    type: DataTypes.DATE,
    defaultValue: () => {
      const now = new Date();
      now.setMonth(now.getMonth() + 1);
      return now;
    },
  },
  usersCount: {
    type: DataTypes.INTEGER,
    defaultValue: 5,
  },
  projectsCount: {
    type: DataTypes.INTEGER,
    defaultValue: 1,
  },
  monthlySDSSearchCount: {
    type: DataTypes.INTEGER,
    defaultValue: 20,
  },
  monthlySDSSaveCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },
  userPrice: {
    type: DataTypes.INTEGER,
  },
  projectPrice: {
    type: DataTypes.INTEGER,
  },
  SDSSavePrice: {
    type: DataTypes.INTEGER,
  },
  SDSSearchPerSavePrice: {
    type: DataTypes.INTEGER,
  },
  monthlySDSSearchUsage: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },
  monthlySDSSaveUsage: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },
  lastUsageUpdate: {
    type: DataTypes.DATE,
    defaultValue: new Date(),
  },
  subscriptionType: {
    type: DataTypes.ENUM,
    defaultValue: "free trial",
    values: ["free trial", "paid"],
  },
});

module.exports = Subscriptions;
