"""Original Poko goal with a bounded cursor budget covering native discovery UI.

The first White discovery can consume the original fifteen-second aiming
budget before ordinary stick input finishes. Give that setup cursor sixty
seconds, keeping its original position tolerance and all actual recruitment,
digging, carry, collection, generated-receipt and goal assertions unchanged.
"""
import asyncio
from pathlib import Path

import test_gameplay_actor_cases as cases
import test_gameplay_digging_cases as digging
from test_gameplay_poko_appraisal import PokoRoute
from test_gameplay_real_server import make_parser


class DiscoveryAwarePokoRoute(PokoRoute):
    def squad_at_actor(self, location, color, count):
        original_aim = self.driver.aim_at

        def discovery_aim(client, target, radius=12, timeout=15):
            return original_aim(client, target, radius=radius, timeout=max(60, timeout))

        self.driver.aim_at = discovery_aim
        try:
            result = super().squad_at_actor(location, color, count)
            self.record('setup-cursor-discovery-budget', self.playable(), location=location,
                        timeout_seconds=60, position_tolerance_unchanged=True,
                        boundary='ordinary PAD cursor/whistle; native discovery UI included in wall time')
            return result
        finally:
            self.driver.aim_at = original_aim


if __name__ == '__main__':
    args = make_parser(__doc__).parse_args()
    args.case = 'poko'
    cases.GoalRoute = DiscoveryAwarePokoRoute
    cases.EXTRA.extend(Path(__file__).with_name(name) for name in digging.EXTRA + (
        'test_gameplay_arrival_policy.py', 'test_gameplay_poko_appraisal.py',
        'test_gameplay_poko_settled_aim.py'))
    asyncio.run(cases.main(args))
