// =======================================================================
// src/routes/api/datanumbers/[movieIndex]/+server.ts (확장자 변경 및 타입 추가)
// =======================================================================
import { json } from '@sveltejs/kit';
import pool from '$lib/server/database';
import type { RequestHandler } from './$types';

export const GET: RequestHandler = async ({ params }) => {
  const { movieIndex } = params;

  try {
    const result = await pool.query<DataNumberInfo>(
      'SELECT "Index", "DataNumber", "LocationFile" FROM public."TumerDatasetRef" WHERE "IndexMovie" = $1 ORDER BY "DataNumber" ASC',
      [movieIndex]
    );
    const dataNumbers = result.rows.map(row => ({
        ...row,
        LocationFile: row.LocationFile.replace(/\\/g, '/')
    }));
    return json(dataNumbers);
  } catch (err) {
    console.error(`API Error fetching data numbers for ${movieIndex}:`, err);
    return json({ error: 'Failed to fetch data numbers' }, { status: 500 });
  }
};