from typing import Union, List

from timeutil import Clock
from datetime import datetime


class ClockStub(Clock):
    def __init__(self, now=None, utc_now=None):
        # type: (Union[datetime, List[datetime]], Union[datetime, List[datetime]]) -> None
        self.now_value = now
        self.now_index = 0
        self.utc_now_value = utc_now
        self.utc_now_index = 0

    def now(self):
        if isinstance(self.now_value, datetime):
            return self.now_value
        else:
            value = self.now_value[self.now_index]
            self.now_index += 1
            if self.now_index >= len(self.now_value):
                self.now_index = 0
            return value

    def utc_now(self):
        if self.utc_now_value is None:
            return self.now()
        else:
            if isinstance(self.utc_now_value, datetime):
                return self.utc_now_value
            else:
                value = self.utc_now_value[self.utc_now_index]
                self.utc_now_index += 1
                if self.utc_now_index >= len(self.utc_now_value):
                    self.utc_now_index = 0
                return value
