module.exports = (sequelize, DataTypes) => {
  const InProcessCheckListDetail = sequelize.define('InProcessCheckListDetail', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    ipc_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'InProcessCheckList',
        key: 'id'
      },
      onDelete: 'CASCADE'
    },
    line_no: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: 'Serial Number'
    },
    item_description: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: 'Item Description'
    },
    drawing_no: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: 'Drawing Number'
    },
    model: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: 'Model'
    },
    qty_per_set: {
      type: DataTypes.DECIMAL(15, 3),
      allowNull: true,
      comment: 'Quantity per Set'
    },
    total_qty: {
      type: DataTypes.DECIMAL(15, 3),
      allowNull: true,
      comment: 'Total Quantity'
    },
    qc_status: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: 'QC Status (OK/NOT OK)'
    },
    remarks: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: 'Remarks'
    }
  }, {
    tableName: 'in_process_checklist_detail',
    underscored: true,
    timestamps: false,
    indexes: [
      { fields: ['ipc_id'] },
      { fields: ['line_no'] }
    ]
  });

  InProcessCheckListDetail.associate = function(models) {
    InProcessCheckListDetail.belongsTo(models.InProcessCheckList, {
      foreignKey: 'ipc_id',
      as: 'checkList'
    });
  };

  return InProcessCheckListDetail;
};
