# -*- coding: utf-8 -*-
# Vol.15は受注済のみ。商談中・未着手はVol.16対象に付け替える。
import json, os
SRC=os.path.join(os.path.dirname(os.path.abspath(__file__)),"meiten-master.json")
with open(SRC,encoding="utf-8") as f: j=json.load(f)
moved=0
for s in j["stores"]:
    v=s.get("vol15")
    if not v: continue
    st=v.get("status")
    if st and st!="受注":
        # Vol.16 へ移設
        s["vol16"]={**v}
        s["vol16"]["targetIssue"]=16
        s.pop("vol15",None)
        # ステータス文字列
        s["status"]= "Vol.16商談中" if st=="商談中" else ("Vol.16見込み" if st=="未着手" else "Vol.16:"+st)
        # 念のためVol.15受注の痕跡を除去
        if 15 in (s.get("issuesPlaced") or []):
            s["issuesPlaced"]=[x for x in s["issuesPlaced"] if x!=15]
        # タグ付け替え
        nt=[]
        for t in s.get("tags",[]):
            if t in ("Vol.15出稿","Vol.15受注","Vol.15商談中","Vol.15未着手"): continue
            nt.append(t)
        nt.append("Vol.16商談中" if st=="商談中" else "Vol.16ターゲット")
        # dedupe
        seen=set(); s["tags"]=[x for x in nt if not (x in seen or seen.add(x))]
        moved+=1
j["_meta"]["vol15Rule"]="2026-06-06: Vol.15=受注済のみ。商談中/未着手はvol16へ移設（CEO指示）。"
with open(SRC,"w",encoding="utf-8") as f: json.dump(j,f,ensure_ascii=False,indent=2)
v15=len([s for s in j["stores"] if 15 in (s.get("issuesPlaced") or [])])
v16=len([s for s in j["stores"] if s.get("vol16")])
print(f"moved to Vol.16: {moved} / now Vol.15(受注)={v15} / Vol.16(商談中+未着手)={v16}")
