from __future__ import annotations
from datetime import datetime, timezone
from typing import Optional
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import BigInteger, Text, String, DateTime, JSON, Boolean, Float
from src.utils.db import Base


class StorePersona(Base):
    """Single table for store brand persona based on LLM analysis."""
    __tablename__ = "store_personas"
    
    id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
    store_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
    branch_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True)
    
    # Core persona fields
    industry: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    audience_type: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    brand_voice: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    content_style: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    
    # LLM analysis metadata
    analysis_summary: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    confidence_score: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
    last_analyzed: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
    
    # System fields
    created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc))
    updated_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc))
    is_active: Mapped[bool] = mapped_column(Boolean, default=True, server_default='true')
