-- C: Comparação de match rate atual (0.80) vs match rate por threshold de similaridade 0.90
WITH base AS (
  SELECT Final_Status,
    Max_Service_Similarity
  FROM `ifood-prev-fraude-case.fraude_biometria.vw_biometry_base`
)
SELECT COUNT(*) AS total_sessoes,
  COUNTIF(Final_Status = 'MATCH') AS match_atual,
  SAFE_DIVIDE(COUNTIF(Final_Status = 'MATCH'), COUNT(*)) AS match_rate_atual,
  COUNTIF(Max_Service_Similarity >= 0.90) AS match_sim_090,
  SAFE_DIVIDE(
    COUNTIF(Max_Service_Similarity >= 0.90),
    COUNT(*)
  ) AS match_rate_sim_090,
  SAFE_DIVIDE(
    COUNTIF(Max_Service_Similarity >= 0.90) - COUNTIF(Final_Status = 'MATCH'),
    NULLIF(COUNTIF(Final_Status = 'MATCH'), 0)
  ) AS delta_relativo_vs_atual
FROM base;