# apps/leave_form_app/api/v1/routes_attachments.py
from __future__ import annotations
import os
import uuid
from flask import Blueprint, request, jsonify

attachments_bp = Blueprint("leave_api_attachments", __name__)


UPLOAD_DIR = "/tmp/leave_app_uploads"
os.makedirs(UPLOAD_DIR, exist_ok=True)

@attachments_bp.post("/attachments/upload-temp")
def upload_temp():
    if "file" not in request.files:
        return jsonify(status="error", message="Missing file"), 400

    f = request.files["file"]
    if not f.filename:
        return jsonify(status="error", message="Empty filename"), 400

    ext = os.path.splitext(f.filename)[1].lower() or ""
    # opcional: validar extensiones
    name = f"{uuid.uuid4().hex}{ext}"
    path = os.path.join(UPLOAD_DIR, name)
    f.save(path)

    return jsonify(status="ok", path=path)
