from pathlib import Path
import importlib.util,shutil,json,sys
from pdf2image import convert_from_path

HERE=Path(__file__).resolve().parent
ROOT=HERE.parents[6]
BASE=ROOT/'oss/local-deliverables/2026-09-23-AI智慧健康站双方案'
spec=importlib.util.spec_from_file_location('brand',HERE.parent/'v3/build.py')
brand=importlib.util.module_from_spec(spec);spec.loader.exec_module(brand)
brand.OUT=BASE/'01-GPT科技产品版';brand.HERE=HERE
brand.DATA=json.loads((HERE/'content.json').read_text())

def tech_hero(c,image,lines,label,sub):
 brand.box(c,0,81,brand.W,446,'#0B111B')
 c.drawImage(str(image),0,brand.H-527,width=brand.W,height=397,mask='auto')
 brand.txt(c,label,34,100,527,10,'#A6CCFF',True)
 brand.txt(c,lines,34,130,430,31,brand.WHITE,True,lead=43)
 sub=sub.replace('健康体检体测一体机','健康体测一体机')
 brand.txt(c,sub,34,230,340,10,'#E0E8F2',False,lead=15)
 if image.name=='product-hero.png':
  brand.txt(c,'运动方案',279,327,52,7.5,'#F3F8FF',True)
  brand.txt(c,'营养方案',279,366,52,7.5,'#FFF2DE',True)
  brand.txt(c,'AI',350,343,30,10,'#FFFFFF',True)
  brand.txt(c,'营养垂类大模型',324,307,108,8.2,'#CCE2FF',True)
  brand.txt(c,'AI运动营养师',180,470,150,10,'#DAEAFE',True)
  brand.txt(c,'健康体测一体机',415,480,145,9,'#DAEAFE',True)
 else:
  brand.txt(c,'数据汇集',253,307,63,8,'#E0EDFF',True)
  brand.txt(c,'执行反馈',253,339,63,8,'#E0EDFF',True)
  brand.txt(c,'运动方案',335,296,68,8,'#E0EDFF',True)
  brand.txt(c,'营养方案',335,316,68,8,'#E0EDFF',True)
  brand.txt(c,'AI',336,344,30,10,'#FFFFFF',True)
  brand.txt(c,'AI Agent',316,384,110,9,'#CCE2FF',True)
  brand.txt(c,'小程序服务',168,470,145,10,'#DAEAFE',True)
  brand.txt(c,'健康体测一体机',416,480,145,9,'#DAEAFE',True)
 brand.txt(c,'实物参考效果图 · 界面为功能示意',388,506,181,6.8,'#BECADA')

brand.hero=tech_hero
(brand.OUT/'assets').mkdir(parents=True,exist_ok=True)
for original,name in [('product-tech-v2.png','product-hero.png'),('channel-tech-v2.png','channel-hero.png')]:
 if not (BASE/'scheme-a'/original).exists():
  if '--product-only' in sys.argv:continue
  raise FileNotFoundError(original)
 shutil.copy2(BASE/'scheme-a'/original,brand.OUT/'assets'/name)
if '--product-only' in sys.argv:
 brand.DATA=brand.DATA[:1]
brand.main()
for pdf in (brand.OUT/'02-图文版').glob('*.pdf'):
 pages=convert_from_path(str(pdf),dpi=200);assert len(pages)==1
 pages[0].save(pdf.with_suffix('.png'))
 print(pdf)
