import datetime
import hashlib


def generate_venezuelan_plate(parking_code, timestamp=None):
    prefix = "PARL"

    # Use current timestamp if not provided
    if timestamp is None:
        timestamp = datetime.datetime.now()

    # Combine parking_code and timestamp to create a unique string
    unique_string = f"{parking_code}{timestamp.isoformat()}"

    # Generate a hash from the unique string
    hash_object = hashlib.md5(unique_string.encode())
    hash_hex = hash_object.hexdigest()

    # Use the first 5 characters of the hash to generate the plate
    hash_subset = hash_hex[:5]

    # Convert first 2 characters to letters (A-Z)
    letters = "".join([chr(65 + int(hash_subset[i], 16) % 26) for i in range(2)])

    # Use last 3 characters for numbers
    numbers = "".join([str(int(hash_subset[i], 16) % 10) for i in range(2, 5)])

    # Combine all parts
    plate = f"{prefix}{letters}{numbers}"

    return plate


def generate_multiple_plates(parking_code, count, start_time=None):
    if start_time is None:
        start_time = datetime.datetime.now()

    plates = []
    for i in range(count):
        timestamp = start_time + datetime.timedelta(seconds=i)
        plates.append(generate_venezuelan_plate(parking_code, timestamp))

    return plates
