-- SilverSight.PIST.Classify — backward-compat shim for 8×8 matrices.
--
-- All classification logic now lives in SilverSight.PIST.ClassifyN.
-- This module re-exports the old API surface under the same names.
--
-- Blending rules (§4) remain here since they are not yet generalized.

import SilverSight.PIST.ClassifyN
import SilverSight.PIST.MatrixN

namespace SilverSight.PIST.Classify

open SilverSight.PIST.ClassifyN
open SilverSight.PIST.MatrixN

-- ── §1  Matrix type ────────────────────────────────────────────────────

abbrev Matrix8 : Type := Array (Array Int)

-- ── §2  Blending rules (not yet generalized) ───────────────────────────

inductive BlendType where
  | additive
  | rms
  | vortex
  deriving Repr

def blend_additive (lam1 lam2 : Int) : Int := max lam1 lam2

def blend_rms (lam1 lam2 : Int) : Int :=
  Int.ofNat (Nat.sqrt (((lam1 * lam1 + lam2 * lam2) / 2).toNat))

def blend_vortex (lam1 lam2 : Int) : Int :=
  (lam1 * lam2) / (lam1 + lam2 + 1)

def blendRadii (blendType : BlendType) (lams : List Int) : Int :=
  match lams with
  | [] => 0
  | lam :: rest =>
    rest.foldl (fun acc lam2 =>
      match blendType with
      | .additive => if acc ≥ lam2 then acc else lam2
      | .rms => isqrt ((acc * acc + lam2 * lam2) / 2)
      | .vortex => (acc * lam2) / (acc + lam2 + 1)
    ) lam

-- ── §3  Classifier surface (delegates to ClassifyN) ────────────────────

def classifyProxy (m : Matrix8) : Option String :=
  ClassifyN.classifyProxy ClassifyN.hashTable8 m

def classifyExact (m : Matrix8) : Option String :=
  ClassifyN.classifyExact 8 m

end SilverSight.PIST.Classify
