const Sequelize = require("sequelize");

module.exports = (db) => {
  const biz_plan = db.define(
    "biz_plan",
    {
      id: {
        type: Sequelize.BIGINT.UNSIGNED,
        primaryKey: true,
        autoIncrement: true,
      },
      plan_code: {
        type: Sequelize.STRING(64),
        allowNull: false,
        unique: true,
      },
      plan_name: {
        type: Sequelize.STRING(128),
        allowNull: false,
        defaultValue: "",
      },
      monthly_price: {
        type: Sequelize.DECIMAL(12, 2),
        allowNull: false,
        defaultValue: 0,
      },
      auth_fee: {
        type: Sequelize.DECIMAL(12, 2),
        allowNull: false,
        defaultValue: 0,
      },
      account_limit: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
      active_user_limit: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
      msg_quota: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
      mass_quota: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
      friend_quota: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
      sns_quota: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
      enabled_features: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: "JSON 功能点白名单",
      },
      allowed_apis: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: "可访问的接口路径列表，如 [\"/user/GetProfile\",\"/message/SendText\"]，null 表示不限制",
      },
      api_call_quota: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "每月 API 总调用次数上限，0=不限制",
      },
      status: {
        type: Sequelize.ENUM("active", "inactive"),
        allowNull: false,
        defaultValue: "active",
      },
    },
    {
      tableName: "biz_plans",
      timestamps: false,
      underscored: true,
      comment: "套餐",
    }
  );
 // biz_plan.sync({ alter: true });
  return biz_plan;
};
