import { moveArtifactToSpace } from '../../../../../../lib/dashboard-spaces.js';

export async function POST(request, { params }) {
  try {
    const { id } = await params;
    const body = await request.json().catch(() => ({}));
    const result = moveArtifactToSpace(body?.artifact_id, id);
    return Response.json(result);
  } catch (err) {
    const status = err?.code === 'SPACE_NOT_FOUND' || err?.code === 'ARTIFACT_NOT_FOUND' ? 404 : 400;
    return Response.json({ error: err?.message || String(err), code: err?.code }, { status });
  }
}
