from faker import Faker
import random
import datetime

fake = Faker()


CANDY_TYPES = ["Starburst", "Skittles", "Reeses", "Snickers", "Smarties", "M&Ms", "Lollipop", "Milky Way", "Sour Patch Kids", "Twix", "Kit Kat", "Swedish Fish"]
CANDY_WEIGHTS = [1/12, 1/12, 2/12, 1/12, 0.5/12, 1/12, 0.25/12, 1/12, 0.5/12, 1/12, 1/12, .75/12]
CANDY_NUMBER = 50
TOTAL_GIVEN = len(CANDY_TYPES) * CANDY_NUMBER * 9 // 10

supply = {candy: CANDY_NUMBER for candy in CANDY_TYPES}

start = datetime.datetime(2023, 10, 31, 18, 00, 00)
end = datetime.datetime(2023, 10, 31, 19, 00, 00)

times = [fake.date_time_between(start, end) for _ in range(TOTAL_GIVEN)]
times.sort()


template = """DROP TABLE IF EXISTS halloween;
CREATE TABLE halloween (
            given_at TIMESTAMP,
            candy TEXT
            );
INSERT INTO halloween VALUES"""

candy_times = []
for time in times:
    candy = random.choices(CANDY_TYPES, weights=CANDY_WEIGHTS, k=1)[0]
    while supply[candy] == 0:
        candy = random.choices(CANDY_TYPES, weights=CANDY_WEIGHTS, k=1)[0]
    supply[candy] -= 1
    candy_times.append(f"('{time:%Y-%m-%d %H:%M:%S}', '{candy}')")


print(template)
print(',\n'.join(candy_times))
print(';')
