import { NextRequest } from 'next/server';
import { proxyToPhpBackend } from '@/lib/api/php-proxy';

/**
 * 특정 페이지 조회 API
 *
 * 엔드포인트: GET /api/tenants/{tenantId}/item-master-config/pages/{pageId}
 */
export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ tenantId: string; pageId: string }> }
) {
  const { tenantId, pageId } = await params;

  return proxyToPhpBackend(
    request,
    `/api/v1/tenants/${tenantId}/item-master-config/pages/${pageId}`,
    { method: 'GET' }
  );
}

/**
 * 특정 페이지 업데이트 API
 *
 * 엔드포인트: PUT /api/tenants/{tenantId}/item-master-config/pages/{pageId}
 */
export async function PUT(
  request: NextRequest,
  { params }: { params: Promise<{ tenantId: string; pageId: string }> }
) {
  const { tenantId, pageId } = await params;
  const body = await request.json();

  return proxyToPhpBackend(
    request,
    `/api/v1/tenants/${tenantId}/item-master-config/pages/${pageId}`,
    {
      method: 'PUT',
      body: JSON.stringify(body),
    }
  );
}

/**
 * 특정 페이지 삭제 API
 *
 * 엔드포인트: DELETE /api/tenants/{tenantId}/item-master-config/pages/{pageId}
 */
export async function DELETE(
  request: NextRequest,
  { params }: { params: Promise<{ tenantId: string; pageId: string }> }
) {
  const { tenantId, pageId } = await params;

  return proxyToPhpBackend(
    request,
    `/api/v1/tenants/${tenantId}/item-master-config/pages/${pageId}`,
    { method: 'DELETE' }
  );
}