// ═══════════════════════════════════════════════════════
// backend/models/training-video.js — NEW FILE
// ═══════════════════════════════════════════════════════
const { DataTypes } = require("sequelize");
const sequelize = require("../db");

const TrainingVideo = sequelize.define("TrainingVideo", {
  title:       { type: DataTypes.STRING, allowNull: false },
  description: { type: DataTypes.TEXT },
  /** Legacy / optional — prefer videoFileName for hosted MP4/WebM */
  youtubeId:   { type: DataTypes.STRING, allowNull: true },
  /** Stored under uploads/training/ (server-hosted video) */
  videoFileName: { type: DataTypes.STRING, allowNull: true },
  category:    {
    type: DataTypes.ENUM(
      "electrical", "fire", "confined-space",
      "height", "chemical", "general"
    ),
    defaultValue: "general",
  },
  targetRoles: { type: DataTypes.JSON },
  // Example: ["electrician", "supervisor", "worker"]
  order:       { type: DataTypes.INTEGER, defaultValue: 0 },
  quizzes:     { type: DataTypes.JSON },
  // Structure: [{ question, options: [], answer: 0 }]
  requiredFor: { type: DataTypes.JSON },
  // Example: ["hot-work", "electrical"] — permit types that require this video
});

module.exports = TrainingVideo;
