#!/usr/bin/env python3
"""
equation_dna_encoder.py — SilverSight Φ Encoder CLI

Thin CLI wrapper around the phi package modules.

Usage:
    echo 'd_F(p,q) = 2*arccos(sum(sqrt(p_i*q_i)))' | python equation_dna_encoder.py
    python equation_dna_encoder.py 'E(x) = x^T Q x'
"""

from __future__ import annotations

import sys

from phi import encode_phi, to_fastq


def main():
    if len(sys.argv) > 1:
        equations = [" ".join(sys.argv[1:])]
    else:
        equations = [line.strip() for line in sys.stdin if line.strip()]

    for eq in equations:
        result = encode_phi(eq)
        if result is None:
            print(f"FAIL: could not parse: {eq!r}", file=sys.stderr)
            continue

        print(f"# Equation: {result['equation']}")
        print(f"# DNA: {result['dna_sequence']}  ({result['length']} bases)")
        print(f"# PASS: {result['consistency_pass']}")
        print(f"# Hash: {result['sha256_prefix']}")
        print(f"# F: {result['F']}")
        print(f"# τ: {result['tau']}")
        print(f"# δ: {result['delta']}")
        print(f"# FASTQ: {to_fastq(result).rstrip()}")
        print()


if __name__ == "__main__":
    main()
