const Sequelize = require("sequelize");

module.exports = (db) => {
  const biz_api_token = db.define(
    "biz_api_token",
    {

      user_id: {
        type: Sequelize.BIGINT.UNSIGNED,
        allowNull: false,
      },
      plan_id: {
        type: Sequelize.BIGINT.UNSIGNED,
        allowNull: true,
      },
      token_name: {
        type: Sequelize.STRING(100),
        allowNull: false,
        defaultValue: "",
      },
      token_hash: {
        type: Sequelize.STRING(64),
        allowNull: false,
        unique: true,
      },
      status: {
        type: Sequelize.ENUM("active", "revoked", "expired"),
        allowNull: false,
        defaultValue: "active",
      },
      expire_at: { type: Sequelize.DATE, allowNull: false },
      last_used_at: { type: Sequelize.DATE, allowNull: true },
    },
    {
      tableName: "biz_api_token",
      freezeTableName: true,
      timestamps: false,
      underscored: true,
    }
  );
  // biz_api_token.sync({ force: true });
  return biz_api_token;
};
