from datetime import datetime
import logging
from typing import List, Optional
from pydantic import BaseConfig
from sqlmodel import Field, SQLModel, Session
import shortuuid
import random
from faker import Faker

# Line items that would be on a receipt
# Each line item has an id, sku, price, quantity, and transaction_id
class LineItem(SQLModel, table=True):
    id: str = Field(default=None, primary_key=True)
    sku: str = Field(foreign_key="product.sku")
    price: float
    quantity: int
    transaction_id: int = Field(foreign_key="transaction.id")

# Each transaction has an id, store_id, date, and total
class Transaction(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    store_id: str = Field(foreign_key="store.id")
    date: datetime
    total: float


# TODO extract real sales data, transform it, and load into db
# for now random data in the correct format will do.
def run(engine):
    # Allow arbitary types for Pydantic validation
    BaseConfig.arbitrary_types_allowed = True

    # Create a fake data generator
    fake = Faker()

    # Create a session to interact with the database
    with 