# typed: strict
# frozen_string_literal: true

module Stats
  # Base class for regression equations with common formatting logic
  class Equation
    extend T::Sig
    extend T::Helpers
    abstract!

    sig { returns(Stats::Axis) }
    attr_reader :x, :y

    sig { params(x: Stats::Axis, y: Stats::Axis).void }
    def initialize(x, y)
      @x = x
      @y = y
    end

    sig { returns(String) }
    def to_s
      format_equation
    end

    # Public method to get coefficients for database storage
    sig { abstract.returns(T::Array[Float]) }
    def coefficients
    end

    # Evaluate the equation for a given x value
    sig(:final) { params(x_value: Float).returns(Float) }
    def evaluate(x_value)
      y.denormalize(evaluate_normalized(x.normalize(x_value)))
    end

    protected

    sig { abstract.params(x_value: Float).returns(Float) }
    def evaluate_normalized(x_value)
    end

    sig { abstract.returns(String) }
    def format_equation
    end
  end
end
