import 'dart:io';
import 'package:backend/extensions/request_context.dart';
import 'package:backend/store.dart';
import 'package:dart_frog/dart_frog.dart';

Response onRequest(RequestContext context, String id) {
  if (context.request.method != HttpMethod.get) {
    return Response(statusCode: HttpStatus.methodNotAllowed);
  }

  final userId = context.userId;

  final translation = MemoryStore.getGoogooTranslation(id, userId);

  if (translation == null) {
    return Response.json(
      statusCode: HttpStatus.notFound,
      body: {'error': 'Translation not found'},
    );
  }

  return Response.json(body: translation.toJson());
}
