# Path: notifications_utils/countries/data.py
# class Postage:
#     UK = 'united-kingdom'
#     FIRST = 'first'
#     SECOND = 'second'
#     EUROPE = 'europe'
#     REST_OF_WORLD = 'rest-of-world'
# 
# Path: notifications_utils/timezones.py
# def convert_utc_to_bst(utc_dt):
#     """
#     Takes a naive UTC datetime and returns a naive London datetime
#     """
#     return pytz.utc.localize(utc_dt).astimezone(local_timezone).replace(tzinfo=None)
# 
# def utc_string_to_aware_gmt_datetime(date):
#     """
#     Date can either be a string, naive UTC datetime or an aware UTC datetime
#     Returns an aware London datetime, essentially the time you'd see on your clock
#     """
#     if not isinstance(date, datetime):
#         date = parser.parse(date)
# 
#     forced_utc = date.replace(tzinfo=pytz.utc)
#     return forced_utc.astimezone(local_timezone)


from collections import namedtuple
from datetime import datetime, time, timedelta
from govuk_bank_holidays.bank_holidays import BankHolidays
from notifications_utils.countries.data import Postage
from notifications_utils.timezones import (
    convert_utc_to_bst,
    utc_string_to_aware_gmt_datetime,
)
import pytz

    # print deadline is 3pm BST
    printed_by = set_gmt_hour(print_day, hour=15)
    now = datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Europe/London'))

    return LetterTimings(
        printed_by=printed_by,
        is_printed=(now > printed_by),
        earliest_delivery=set_gmt_hour(earliest_delivery, hour=16),
        latest_delivery=set_gmt_hour(latest_delivery, hour=16),
    )


def letter_can_be_cancelled(notification_status, notification_created_at):
    '''
    If letter does not have status of created or pending-virus-check
        => can't be cancelled (it has already been processed)

    If it's after 5.30pm local time and the notification was created today before 5.30pm local time
        => can't be cancelled (it will already be zipped up to be sent)
    '''
    if notification_status not in ('created', 'pending-virus-check'):
        return False

    if too_late_to_cancel_letter(notification_created_at):
        return False
    return True


def too_late_to_cancel_letter(notification_created_at):

# Path: notifications_utils/countries/data.py
# class Postage:
#     UK = 'united-kingdom'
#     FIRST = 'first'
#     SECOND = 'second'
#     EUROPE = 'europe'
#     REST_OF_WORLD = 'rest-of-world'
# 
# Path: notifications_utils/timezones.py
# def convert_utc_to_bst(utc_dt):
#     """
#     Takes a naive UTC datetime and returns a naive London datetime
#     """
#     return pytz.utc.localize(utc_dt).astimezone(local_timezone).replace(tzinfo=None)
# 
# def utc_string_to_aware_gmt_datetime(date):
#     """
#     Date can either be a string, naive UTC datetime or an aware UTC datetime
#     Returns an aware London datetime, essentially the time you'd see on your clock
#     """
#     if not isinstance(date, datetime):
#         date = parser.parse(date)
# 
#     forced_utc = date.replace(tzinfo=pytz.utc)
#     return forced_utc.astimezone(local_timezone)


# Path: notifications_utils/letter_timings.py
from collections import namedtuple
from datetime import datetime, time, timedelta
from govuk_bank_holidays.bank_holidays import BankHolidays
from notifications_utils.countries.data import Postage
from notifications_utils.timezones import (
    convert_utc_to_bst,
    utc_string_to_aware_gmt_datetime,
)
import pytz


    # print deadline is 3pm BST
    printed_by = set_gmt_hour(print_day, hour=15)
    now = datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Europe/London'))

    return LetterTimings(
        printed_by=printed_by,
        is_printed=(now > printed_by),
        earliest_delivery=set_gmt_hour(earliest_delivery, hour=16),
        latest_delivery=set_gmt_hour(latest_delivery, hour=16),
    )


def letter_can_be_cancelled(notification_status, notification_created_at):
    '''
    If letter does not have status of created or pending-virus-check
        => can't be cancelled (it has already been processed)

    If it's after 5.30pm local time and the notification was created today before 5.30pm local time
        => can't be cancelled (it will already be zipped up to be sent)
    '''
    if notification_status not in ('created', 'pending-virus-check'):
        return False

    if too_late_to_cancel_letter(notification_created_at):
        return False
    return True


def too_late_to_cancel_letter(notification_created_at):

    time_created_at = convert_utc_to_bst(notification_created_at)