/**
 * Tabela 10 — Cpe para telhados múltiplos, simétricos, de tramos
 * iguais, com h ≤ a' (NBR 6123:2023, sec. 6.1.1).
 *
 * Fonte: NBR 6123:2023, p. 24 (Tabela 10).
 * Última auditoria: 2026-07-08 — valores exatos do PDF implementados.
 */

import { linearInterp1D } from '../log-interp';

const THETA = [5, 10, 20, 30, 45] as const;

export interface MultiSpanSymmetricCpe {
  a_star: number;
  b_star: number;
  c_star: number;
  d_star: number;
  m_star: number;
  n_star: number;
  x_star: number;
  z_star: number;
  b1: number;
  b2: number;
  b3: number;
}

const ALPHA_0 = {
  a_star: [-0.9, -1.1, -0.7, -0.2, +0.3],
  b_star: [-0.6, -0.6, -0.6, -0.6, -0.6],
  c_star: [-0.4, -0.4, -0.4, -0.4, -0.6],
  d_star: [-0.3, -0.3, -0.3, -0.3, -0.4],
  m_star: [-0.3, -0.3, -0.3, -0.2, -0.2],
  n_star: [-0.3, -0.3, -0.3, -0.3, -0.4],
  x_star: [-0.3, -0.3, -0.3, -0.2, -0.2],
  z_star: [-0.3, -0.4, -0.5, -0.5, -0.5],
};

function interp(values: readonly number[], theta: number): number {
  return Number(linearInterp1D(THETA, [...values], theta).toFixed(2));
}

export function getMultiSpanSymmetricCpeNBR6123(theta: number): MultiSpanSymmetricCpe {
  const t = Math.max(THETA[0], Math.min(THETA[THETA.length - 1], theta));

  return {
    a_star: interp(ALPHA_0.a_star, t),
    b_star: interp(ALPHA_0.b_star, t),
    c_star: interp(ALPHA_0.c_star, t),
    d_star: interp(ALPHA_0.d_star, t),
    m_star: interp(ALPHA_0.m_star, t),
    n_star: interp(ALPHA_0.n_star, t),
    x_star: interp(ALPHA_0.x_star, t),
    z_star: interp(ALPHA_0.z_star, t),
    b1: -0.8,
    b2: -0.6,
    b3: -0.2,
  };
}