import datetime

from models.enums import ContainerLength, ContainerType

PAYMENT_SCHEMA = {
    "standart": [[0, 5, 25], [5, 20, 40], [40, 1000000, 75]],
    "reefer": [[0, 7, 35], [7, 30, 60], [30, 1000000, 115]],
}


def calc_storage_amount(depot, container):
    result = (depot.expedited_on - depot.received_on + datetime.timedelta(days=1)).days
    if container.container_type == ContainerType.ct_reefer:
        data = PAYMENT_SCHEMA["reefer"]
        result -= 1
    else:
        data = PAYMENT_SCHEMA["standart"]

    for i in data:
        start, end, price = i
        if start <= result < end:
            price_per_day = price
            break
    if container.container_length in (
        ContainerLength.cl_40_ft,
        ContainerLength.cl_45_ft,
    ):
        result *= 2
    result = result * price_per_day
    return result
