from sqlalchemy import String, Integer, Float, Date, Boolean
from sqlalchemy.orm import Mapped, mapped_column
from app.core.models import BaseModel


class Holiday(BaseModel):
    """
    Represents an official non-working day.
    
    Holidays are excluded from leave duration and working day calculations.
    """
    __tablename__ = 'hris_holiday'

    name: Mapped[str] = mapped_column(String(100), nullable=False)
    date: Mapped[Date] = mapped_column(Date, nullable=False)
    is_recurring: Mapped[bool] = mapped_column(Boolean, default=False) # e.g., Christmas

    def __repr__(self):
        return f"<Holiday {self.name} {self.date}>"

class SalaryComponent(BaseModel):
    """
    Master data for salary building blocks (Allowances and Deductions).
    
    Calculation types:
    - 'fixed_amount': A set numeric value.
    - 'percentage_gross': Calculated based on the base salary.
    - 'per_occurrence': Multiplied by specific events (e.g., overtime hours, late days).
    """
    __tablename__ = 'hris_salary_component'

    name: Mapped[str] = mapped_column(String(100), nullable=False)
    type: Mapped[str] = mapped_column(String(20), nullable=False) # earning, deduction
    calculation_type: Mapped[str] = mapped_column(String(20), default='fixed_amount')
    is_mandatory: Mapped[bool] = mapped_column(Boolean, default=False)
    is_taxable: Mapped[bool] = mapped_column(Boolean, default=True)
    default_amount: Mapped[float] = mapped_column(Float, default=0.0)

    def __repr__(self):
        return f"<SalaryComponent {self.name} ({self.type})>"
