#!/usr/bin/env python3
import os
import shlex
import shutil
import subprocess
import sys

MAX_N = 2 * 10**5
MAX_C = 10**6



MAKE_DATA = len(sys.argv) >= 2 and sys.argv[1] == 'makedata'
CASE = 1
manual_cases = set()
def add_case(name, cmd):
    print('      - %s: %s' % (name, cmd))
    if os.path.isfile(cmd) and os.path.splitext(cmd)[1] == '.in':
        manual_cases.add(cmd)
    if MAKE_DATA:
        global CASE
        dst = os.path.join('..', 'data', 'secret', '%02d-%s.in' % (CASE, name))
        CASE += 1
        if cmd in manual_cases:
            shutil.copyfile(cmd, dst)
            sys.stderr.write('Copying %s to %s\n' % (cmd, dst))
        else:
            cmd = shlex.split(cmd)
            cmd[0] = './' + cmd[0]
            sys.stderr.write('Running %s > %s\n' % (cmd, dst))
            with open(dst, 'w') as f:
                subprocess.run(cmd, stdout=f, check=True)



print('''## AUTO-GENERATED BY gen-yaml.py, DO NOT EDIT
solution: /submissions/accepted/per.cc

data:
  sample:
    type: directory
    solution:
    data:
      '1':
      '2':
      '3':

  secret:
    type: directory
    data:''')

add_case('single-star', 'uniform.py --maxn 1 --seed 99')
for x in ['diagonal-up-tiny',
          'diagonal-down-tiny',
          'diagonal-up-long',
          'diagonal-down-long',
          'almostdiag-up1',
          'almostdiag-up2',
          'almostdiag-down1',
          'almostdiag-down2',
          'vertical',
          'horizontal']:
    add_case(x, 'manual/' + x + '.in')

for i in range(10):
    add_case('uniform-small' , 'uniform.py --maxn 10 --maxc 100 --seed %d' % i)

for i in range(10):
    add_case('diagonal-small' , 'diagonal.py --maxn 10 --maxc 100 --seed %d' % (i+10))
    
for i in range(5):
    add_case('uniform-medium' ,'uniform.py --maxn 1000 --maxc 10000 --seed %d' % (i+20))

for i in range(3):
    add_case('uniform-large' ,'uniform.py --seed %d' % (i+30))
    
for i in range(1):
    add_case('uniform-max' ,'uniform.py --minn %d --seed %d' % (MAX_N, i+40))
    
for i in range(1):
    add_case('uniform-max-boundary' ,'uniform.py --minn %d --minc %d --seed %d' % (MAX_N, MAX_C, i+60))
    
for i in range(1):
    add_case('diagonal-max' ,'diagonal.py --minn %d --seed %d' % (MAX_N, i+50))

add_case('max-answer', 'manual/maxanswer.in')



print('#     Before editing this file, read comment on first line of file.')

for (p, _, files) in os.walk('manual'):
    for f in files:
        path = os.path.join(p, f)
        if path not in manual_cases:
            sys.stderr.write('Manual case %s not added, did you forget it?\n' % path)
