const Sequelize = require("sequelize");

module.exports = (db) => {
  const biz_user = db.define(
    "biz_user",
    {
      id: {
        type: Sequelize.BIGINT.UNSIGNED,
        primaryKey: true,
        autoIncrement: true,
      },
      name: {
        type: Sequelize.STRING(100),
        allowNull: false,
        defaultValue: "",
        comment: "姓名/称呼",
      },
      mobile: {
        type: Sequelize.STRING(20),
        allowNull: true,
        comment: "手机号",
      },
      email: {
        type: Sequelize.STRING(120),
        allowNull: true,
      },
      company_name: {
        type: Sequelize.STRING(200),
        allowNull: true,
        comment: "公司名",
      },
      status: {
        type: Sequelize.ENUM("active", "disabled"),
        allowNull: false,
        defaultValue: "active",
      },
    },
    {
      // 与库表名一致：单数 biz_user（与模型名一致，避免部分环境下 tableName 未生效时落到默认表名 biz_user）
      tableName: "biz_user",
      freezeTableName: true,
      timestamps: false,
      underscored: true,
      comment: "业务用户",
    }
  );
  // biz_user.sync({ alter: true });

  return biz_user;
};
