# typed: strict
# frozen_string_literal: true

module Stats
  class Axis
    extend T::Sig
    extend T::Helpers
    abstract!

    sig { returns(Float) }
    attr_reader :min

    sig { returns(Float) }
    attr_reader :max

    sig(:final) { params(min: Float, max: Float).void }
    def initialize(min:, max:)
      @min = min
      @max = max
    end

    sig(:final) { returns(Float) }
    def scale
      max - min
    end

    sig(:final) { returns(T::Range[Float]) }
    def range
      min..max
    end

    sig { abstract.params(value: Float).returns(Float) }
    def normalize(value)
    end

    sig { abstract.params(value: Float).returns(Float) }
    def denormalize(value)
    end

    sig(:final) do
      params(
        mapper: T.nilable(T.proc.params(arg: Float).returns(String)),
      ).returns(String)
    end
    def as_string(&mapper)
      mapper ||= ->(x) { x }
      "#{mapper.call(min)} to #{mapper.call(max)}"
    end
  end
end
