const { DataTypes } = require("sequelize");
const sequelize = require("../db");

const TrainingLesson = sequelize.define("TrainingLesson", {
  title: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  description: {
    type: DataTypes.TEXT,
  },
  videoFileName: {
    type: DataTypes.STRING,
    comment: "Uploaded video file (MP4/WebM)",
  },
  youtubeId: {
    type: DataTypes.STRING,
    comment: "Legacy YouTube video ID",
  },
  duration: {
    type: DataTypes.INTEGER,
    comment: "Video duration in minutes",
  },
  watchUnlockPercent: {
    type: DataTypes.INTEGER,
    defaultValue: 80,
    comment: "Percentage to watch before unlocking quiz",
  },
  order: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },
  // TrainingModuleId added via association
}, {
  freezeTableName: true,
  tableName: 'TrainingLessons'
});

module.exports = TrainingLesson;
