from sqlalchemy.orm import Session

from app.models.reimbursement import ReimbursementRequest


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

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

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

    def create(self, request: ReimbursementRequest) -> ReimbursementRequest:
        self.db.add(request)
        self.db.commit()
        self.db.refresh(request)
        return request
