#!/usr/bin/env python3
"""Print the page-side FIX queue for the port (kills whose FIX step isn't ticked), earliest batch first.
Usage: python3 _tools/fix_queue.py smg ar          (weapons)   |   python3 _tools/fix_queue.py --all"""
import json, sys, os
st = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'coord', 'port_batches.json')))
ws = set(sys.argv[1:]) - {'--all'}
rows = [(v['batch'], {'READY': 0, 'FIXABLE': 0, 'NEW-FLAGGED': 1, 'REWORK': 2}[v['status']], k, v) for k, v in st['kills'].items()
        if not v.get('gone') and (v['status'] in ('FIXABLE', 'REWORK', 'NEW-FLAGGED') or v.get('pre') == 'FAIL') and 'fix' not in v['checks']
        and ('--all' in sys.argv or v['weapon'] in ws)]
for b, _, k, v in sorted(rows):
    print(f"B{b:<2} {v['status']:<11} {k:<34} {v['name']}\n      fix: {v['fix']}" + (f"\n      note: {v['note']}" if v['note'] else ''))
print(f"{len(rows)} kills")
