from typing import Optional
from uuid import UUID, uuid4
from datetime import datetime

from sqlalchemy import Column
from sqlalchemy.dialects.postgresql import JSONB
from sqlmodel import SQLModel, Field


class BulkAddressUpload(SQLModel, table=True):
    __tablename__ = "bulk_address_uploads"

    id: UUID = Field(default_factory=uuid4, primary_key=True, index=True)
    portfolio_id: str = Field(nullable=False)
    user_id: str = Field(nullable=False)
    s3_bucket: str = Field(nullable=False)
    s3_key: str = Field(nullable=False)
    filename: str = Field(nullable=False)
    status: str = Field(default="ready_for_processing", nullable=False)
    column_mapping: Optional[dict] = Field(default=None, sa_column=Column(JSONB))
    task_id: Optional[UUID] = Field(default=None)
    combined_output_s3_uri: Optional[str] = Field(default=None)
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow)
