"""Read-only PCM WAV inventory plus user-supplied hypothetical arithmetic."""
import wave,json,sys
from decimal import Decimal
from pathlib import Path
def inventory(paths,rate=None):
    files=[];total=Decimal(0)
    for p in paths:
        with wave.open(str(p),'rb') as w:
            duration=Decimal(w.getnframes())/Decimal(w.getframerate())
            files.append({'file':Path(p).name,'frames':w.getnframes(),'sampleRateHz':w.getframerate(),'channels':w.getnchannels(),'seconds':str(duration)})
            total+=duration
    minutes=total/Decimal(60)
    return {'scope':'Local PCM WAV headers and hypothetical flat per-minute arithmetic; no transcription performed','files':files,'totalSeconds':str(total),'totalMinutes':str(minutes),'assumedCurrency':None,'assumedRatePerMinute':rate,'hypotheticalRawUsageCost':None if rate is None else str(minutes*Decimal(rate)),'excluded':['minimums','rounding increments','subscription base','retry billing','channels billing rules','storage','review labor','tax','FX'],'providerOperations':0}
if __name__=='__main__':
    paths=[x for x in sys.argv[1:] if not x.startswith('--rate=')]
    rate=next((x.split('=',1)[1] for x in sys.argv[1:] if x.startswith('--rate=')),None)
    if rate is not None and (not Decimal(rate).is_finite() or Decimal(rate)<0):raise SystemExit('Rate must be finite and nonnegative')
    print(json.dumps(inventory(paths,rate),sort_keys=True,indent=2))
