import uuid
from datetime import datetime, date, timezone
from sqlalchemy import String, Integer, Date, DateTime, Text, ForeignKey
from typing import List, Optional
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.database import Base


class SalaryHistory(Base):
    __tablename__ = "salary_history"

    id: Mapped[str] = mapped_column(
        String, primary_key=True, default=lambda: str(uuid.uuid4())
    )
    employee_id: Mapped[str] = mapped_column(
        String, ForeignKey("employees.id", ondelete="CASCADE"), nullable=False
    )
    old_salary: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
    new_salary: Mapped[int] = mapped_column(Integer, nullable=False)
    effective_date: Mapped[date] = mapped_column(Date, nullable=False)
    notes: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    created_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
    )

    employee: Mapped["Employee"] = relationship(
        "Employee", back_populates="salary_history"
    )
