from sqlalchemy.orm import Session

from app.models.employee import Employee


class EmployeeRepository:
    def __init__(self, db: Session) -> None:
        self.db = db

    def list(self) -> list[Employee]:
        return self.db.query(Employee).order_by(Employee.created_at.desc()).all()

    def get(self, employee_id: str) -> Employee | None:
        return self.db.query(Employee).filter(Employee.id == employee_id).first()

    def create(self, employee: Employee) -> Employee:
        self.db.add(employee)
        self.db.commit()
        self.db.refresh(employee)
        return employee
