const mongoose = require('mongoose');
const { tenantFields, applyPlatformPlugins } = require('../platformFields');

const schema = new mongoose.Schema({
  ...tenantFields,
  formDefinition: { type: mongoose.Schema.ObjectId, ref: 'FormDefinition', required: true, autopopulate: true },
  key: { type: String, required: true },
  label: { type: String, required: true },
  type: { type: String, enum: ['text', 'textarea', 'number', 'select', 'checkbox', 'date', 'email', 'phone'], default: 'text' },
  required: { type: Boolean, default: false },
  options: [String],
  placeholder: String,
  order: { type: Number, default: 0 },
});

module.exports = mongoose.model('FormFieldDefinition', applyPlatformPlugins(schema));
