content: package org.hiast.batch.domain.model;
  
  import org.apache.spark.sql.Dataset;
  import org.apache.spark.sql.Row;
  import org.hiast.ids.MovieId;
  import org.hiast.ids.UserId;
  import org.hiast.model.factors.ItemFactor;
  import org.hiast.model.factors.UserFactor;
  
  import java.util.List;
  
  /**
   * A container for the user and item factors generated by the ALS model.
   * This class now supports both Spark-specific Dataset representations and
   * the generic factor models from shared-kernel.
   */
  public class ModelFactors {
      // Spark-specific representations
      private final Dataset<Row> userFactorsDataset; // Schema: (userId: int, features: vector)
      private final Dataset<Row> itemFactorsDataset; // Schema: (itemId: int, features: vector)
  
      // Generic factor model representations
      private List<UserFactor<float[]>> userFactors;
      private List<ItemFactor<float[]>> itemFactors;
  
      /**
       * Constructor that takes Spark Datasets.
       *
       * @param userFactorsDataset Dataset containing user factors
       * @param itemFactorsDataset Dataset containing item factors
       */
      public ModelFactors(Dataset<Row> userFactorsDataset, Dataset<Row> itemFactorsDataset) {
          this.userFactorsDataset = userFactorsDataset;
          this.itemFactorsDataset = itemFactorsDataset;
      }
  
      /**
       * Constructor that takes generic factor model lists.
       *
       * @param userFactors List of UserFactor objects
       * @param itemFactors List of ItemFactor objects
       */
      public ModelFactors(List<UserFactor<float[]>> userFactors, List<ItemFactor<float[]>> itemFactors) {
          this.userFactorsDataset = null;
          this.itemFactorsDataset = null;
          this.userFactors = userFactors;
          this.itemFactors = itemFactors;
      }
  
      /**
       * Gets the Spark Dataset representation of user factors.
       *
       * @return Dataset containing user factors
       */
      public Dataset<Row> getUserFactorsDataset() {
          return userFactorsDataset;
      }
  
      /**
       * Gets the Spark Dataset representation of item factors.
       *
       * @return Dataset containing item factors
       */
      public Dataset<Row> getItemFactorsDataset() {
          return itemFactorsDataset;
      }
  
      /**
       * Gets the generic user factors.
       *
       * @return List of UserFactor objects
       */
      public List<UserFactor<float[]>> getUserFactors() {
          return userFactors;
      }
  
      /**
       * Gets the generic item factors.
       *
       * @return List of ItemFactor objects
       */
      public List<ItemFactor<float[]>> getItemFactors() {
          return itemFactors;
      }
  
      /**
       * Sets the generic user factors.
       *
       * @param userFactors List of UserFactor objects
       */
      public void setUserFactors(List<UserFactor<float[]>> userFactors) {
          this.userFactors = userFactors;
      }
  
      /**
       * Sets the generic item factors.
       *
       * @param itemFactors List of ItemFactor objects
       */
      public void setItemFactors(List<ItemFactor<float[]>> itemFactors) {
          this.itemFactors = itemFactors;
      }
  
      /**
       * Checks if this ModelFactors instance has Spark Dataset representations.
       *
       * @return true if it has Dataset representations, false otherwise
       */
      public boolean hasDatasetRepresentations() {
          return userFactorsDataset != null && itemFactorsDataset != null;
      }
  
      /**
       * Checks if this ModelFactors instance has generic factor model representations.
       *
       * @return true if it has generic factor model representations, false otherwise
       */
      public boolean hasGenericFactorRepresentations() {
          return userFactors != null && itemFactors != null;
      }
  }