# -*- coding: utf-8 -*-

#
# Copyright Adam Pritchard 2020
# MIT License : https://adampritchard.mit-license.org/
#

"""
Functions and classes to be used for accessing the data stored in Google Sheets.

Google is inconsistent with terminology for "sheets" stuff. We're going to use
"sheet" or "spreadsheet" to mean the whole document/file and "worksheet" to mean the
tabs of data in a spreadsheet.

Note that nothing here is terribly robust. For example, sheet rows are gathered and then
modified or deleted based on the row number at the time of extraction. But if another
deletion happened in between, the number would be off and the wrong rows would be changed
after. This is okay for our very small user-base with very limited middle-of-the-night
deletion occurring, but isn't good enough for a real application.
"""

from __future__ import annotations
from typing import Tuple, Callable, Optional, Union, List
import itertools
import json
import logging
from googleapiclient.discovery import build
from googleapiclient.discovery_cache.base import Cache
from google.oauth2 import service_account

import config


# from https://github.com/googleapis/google-api-python-client/issues/325#issuecomment-274349841
class MemoryCache(Cache):
    _CACHE = {}

    def get(self, url):