import { A, buildContract } from '@jig-software/trest-core';
import { objectId } from '@jig-software/zod-bson';
import { ReportFile, ReportIntention } from '../schemas';

export const reportFileContract = buildContract((c) =>
  c
    .prefix('/report-files')
    .parse((p) => p.error.text(400).error.text(401))
    .endpoints({
      createReport: (e) =>
        e
          .method('POST')
          .prepare((p) => p.body.json(ReportIntention).annotate<[init: A]>())
          .parse((p) => p.success.object(201, ReportFile)),
      downloadReportFile: (e) =>
        e
          .method('GET')
          .path('/:_id/content')
          .prepare((p) => p.param('_id', objectId()).annotate<[_id: A]>())
          .parse((p) => p.success.file(200).error.text(404)),
    }),
);
