import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../utils/sequelize.js';

class Blog extends Model {}

Blog.init({
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'user_id'
  },
  title: {
    type: DataTypes.STRING(255),
    allowNull: false},
  description: {
    type: DataTypes.TEXT,
    allowNull: true},
  // 'public' or 'logged_in'
  visibility: {
    type: DataTypes.STRING(20),
    allowNull: false,
    defaultValue: 'public'},
  ageMin: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'age_min'
  },
  ageMax: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'age_max'
  },
  // 'm' | 'f' | null; comma-separated for future-proofing (e.g., 'm,f')
  genders: {
    type: DataTypes.STRING(10),
    allowNull: true},
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    field: 'created_at'
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    field: 'updated_at'
  }
}, {
  sequelize,
  modelName: 'Blog',
  tableName: 'blog',
  schema: 'community',
  timestamps: true,
  underscored: true});

export default Blog;
