from sys import stderr
from .enums import FileTypeEnum
from .abstractions import AApiService, AFetcher
from .context import Context
from .factory import Creator
from .fetcher import Fetcher
from typing import Generator
from .models import Todo


class ApiService(AApiService):
    def __init__(self, fetcher: AFetcher):
        self.fetcher = fetcher

    def fetch_data(self) -> Generator[Todo, None, None]:
        return self.fetcher.get_todos()

    def run(self, format: FileTypeEnum = FileTypeEnum.CSV) -> None:
        print("Running ApiService", file=stderr)
        data: Generator[Todo, None, None] = self.fetch_data()
        context: Context = Creator().create_object(data, format)
        context.request()
        print("End Running ApiService", file=stderr)

from sys import stderr
from .enums import FileTypeEnum
from .abstractions import AApiService, AFetcher
from .context import Context
from .factory import Creator
from .fetcher import Fetcher
from typing import Generator
from .models import Todo


class ApiService(AApiService):
    def __init__(self, fetcher: AFetcher):
        self.fetcher = fetcher

    def fetch_data(self) -> Generator[Todo, None, None]:
        return self.fetcher.get_todos()

    def run(self, format: FileTypeEnum = FileTypeEnum.CSV) -> None:
        print("Running ApiService", file=stderr)
        data: Generator[Todo, None, None] = self.fetch_data()
        context: Context = Creator().create_object(data, format)
        context.request()
        print("End Running ApiService", file=stderr)
