import { buildContract } from '@jig-software/trest-core';
import { z } from 'zod';
import { Event } from '../schemas';
import { QueryPagination } from './common';

export const ListEventDto = Event.pick({
  username: true,
  connectingIp: true,
  type: true,
}).merge(QueryPagination);
export type ListEventDto = z.infer<typeof ListEventDto>;

export const eventContract = buildContract((c) =>
  c
    .prefix('events')
    .parse((p) =>
      p.error.text(500).error.text(400).error.text(401).error.text(403),
    )
    .endpoints({
      listEvents: (e) =>
        e
          .method('GET')
          .prepare((p) => p.query(ListEventDto))
          .parse(
            (p) => p.success.object(200, z.array(z.object({}).passthrough())), // TODO: set zod schema
          ),
    }),
);
