import enum
from sqlalchemy import String, Integer, Numeric, Enum as SQLAlchemyEnum
from sqlalchemy.orm import Mapped, mapped_column
from app.core.models import BaseModel

class PtkpStatus(enum.Enum):
    """
    Indonesian PTKP (Penghasilan Tidak Kena Pajak) Statuses.
    
    Format:
    - TK/x: Tidak Kawin (Not Married), x children.
    - K/x: Kawin (Married), x children.
    - K/I/x: Kawin, Istri digabung (Married, Wife's income merged), x children.
    """
    TK0 = "TK/0"
    TK1 = "TK/1"
    TK2 = "TK/2"
    TK3 = "TK/3"
    K0 = "K/0"
    K1 = "K/1"
    K2 = "K/2"
    K3 = "K/3"
    KI0 = "K/I/0"
    KI1 = "K/I/1"
    KI2 = "K/I/2"
    KI3 = "K/I/3"

class TerCategory(enum.Enum):
    """
    Indonesian TER (Tarif Efektif Rata-rata) Categories.
    
    - Category A: For PTKP statuses TK/0, TK/1, K/0.
    - Category B: For PTKP statuses TK/2, TK/3, K/1, K/2.
    - Category C: For PTKP status K/3.
    """
    A = "A"
    B = "B"
    C = "C"

class Pph21TerRate(BaseModel):
    """
    Lookup table for PPh21 TER (Tarif Efektif Rata-rata) rates.
    
    Used to calculate monthly income tax based on the employee's 
    gross income and their TER category (derived from PTKP status).
    """
    __tablename__ = 'hris_pph21_ter_rates'

    category: Mapped[TerCategory] = mapped_column(SQLAlchemyEnum(TerCategory), nullable=False)
    gross_income_min: Mapped[float] = mapped_column(Numeric(15, 2), nullable=False)
    gross_income_max: Mapped[float] = mapped_column(Numeric(15, 2), nullable=False)
    rate_percent: Mapped[float] = mapped_column(Numeric(5, 3), nullable=False) # e.g., 2.500%

    def __repr__(self):
        return f"<TER {self.category.name} {self.rate_percent}%>"
