from typing import Dict, List, Optional, Set, Tuple

from .available_docs import UrlDocsCVM
from .available_years import AvailableYearsCVM


class DictZipsToDownloadCVM:
    def __init__(self):
        self._url_docs = UrlDocsCVM()
        self._available_years = AvailableYearsCVM()

    def get_dict_zips_to_download(
        self,
        list_docs: Optional[List[str]] = None,
        initial_year: Optional[int] = None,
        last_year: Optional[int] = None,
    ) -> Tuple[Dict[str, List[str]], Set[str]]:
        """
        Gets a dictionary of zip files to download.

        Args:
            list_docs: A list of document types to download.
            initial_year: The initial year for the download.
            last_year: The last year for the download.

        Returns:
            A tuple containing a dictionary of zip files to download and a set of document types.
        """
        range_years: range = self._available_years.return_range_years(
            initial_year, last_year
        )

        dict_urls_docs, set_docs = self._url_docs.get_url_docs(list_docs)

        dict_zips_to_download: Dict[str, List[str]] = {
            doc: [url + str(year) + '.zip' for year in range_years]
            for doc, url in dict_urls_docs.items()
        }

        return dict_zips_to_download, set_docs
