from typing import Tuple
from typing import List


def read_plain_txt(input_fn: str) -> Tuple[List[str], List[str]]:
    """
    Parses the input_fn and returns a tuple of two lists of strings,
    holding the migrations and queries respectively.

    Formally,
    (
        [
            <english str>,
            ...
        ],
        [
            <english str>,
            ...
        ]
    )

    """

    with open(input_fn, 'r') as f:
        migrations = []
        queries = []
        mode = 'none'
        for line in f:
            stripped = line.strip()
            if len(stripped) == 0:
                continue
            if stripped.lower() == '== migrations':
                if mode != 'none':
                    raise ValueError(f'Invalid {input_fn}: The migrations section should appear first.')
                mode = 'migrations'
            elif stripped.lower() == '== queries':
                if mode != 'migrations':
                    raise ValueError(f'Invalid {input_fn}: The queries section should appear after the migrations section.')
                mode = 'queries'
            elif stripped[0] == '#':
                pass
            else:
                if mode == 'migrations':
                    migrations.append(stripped)
                elif mode == 'queries':
                    queries.append(stripped)
                else:
                    pass
        return migrations, queries