"""Abstract provider interface. Concrete providers live next to this file.""" import asyncio import logging from abc import ABC, abstractmethod from dataclasses import dataclass from actions import Recorder from classes.application_result import ApplicationResult from classes.profile import Profile logger = logging.getLogger("flat-apply") @dataclass class ApplyContext: """Per-request state passed into every provider call.""" profile: Profile submit_forms: bool recorder: Recorder class Provider(ABC): @property @abstractmethod def domain(self) -> str: ... @abstractmethod async def apply_for_flat(self, url: str, ctx: ApplyContext) -> ApplicationResult: ... def test_apply(self, url, profile: Profile | None = None, submit_forms: bool = False): rec = Recorder(url) ctx = ApplyContext(profile or Profile(), submit_forms=submit_forms, recorder=rec) result = asyncio.run(self.apply_for_flat(url, ctx)) print(repr(result)) return result, rec.to_json()