import { getRouterParam } from 'h3';

import { getMediaMessageById } from '~/utils/media-repository';
import { useResponseError, useResponseSuccess } from '~/utils/response';

export default defineEventHandler((event) => {
  const idParam = getRouterParam(event, 'id');
  const id = idParam ? Number.parseInt(idParam, 10) : NaN;

  if (!Number.isInteger(id)) {
    return useResponseError('媒体ID不合法', -1);
  }

  const media = getMediaMessageById(id);

  if (!media) {
    return useResponseError('未找到对应的媒体记录', -1);
  }

  return useResponseSuccess(media);
});

