# typed: true
class CreateTrainedRegressionModels < ActiveRecord::Migration[7.2]
  def change
    mirai_tablespace!

    create_table :trained_regression_models do |t|
      # Model identification and metadata
      t.string :name, null: false
      t.text :description
      t.string :model_type, null: false # linear, quadratic, logarithmic, square_root

      # Data source information
      t.integer :total_records_count, null: false
      t.integer :training_records_count, null: false
      t.integer :evaluation_records_count, null: false
      t.float :train_test_split_ratio, null: false, default: 0.8
      t.integer :random_seed, null: false, default: 42
      t.integer :max_points_limit # null means no limit

      # Normalizer parameters for reconstruction
      t.float :x_min, null: false
      t.float :x_max, null: false
      t.float :y_min, null: false
      t.float :y_max, null: false

      # Trained coefficients (stored as JSON array)
      t.jsonb :coefficients, null: false, default: []

      # Performance metrics
      t.float :training_r_squared, null: false
      t.float :evaluation_r_squared, null: false

      # Model equation in human-readable format
      t.text :equation_string, null: false

      # Additional metadata
      t.jsonb :metadata, default: {} # for any additional info

      t.timestamps

      # Indexes for efficient querying
      t.index :name
      t.index :model_type
      t.index :created_at
      t.index :training_r_squared
      t.index :evaluation_r_squared
    end
  end
end
