import { router } from "@repo/core-shared/trpc/init";

import { mediaContainer } from "../../di/container";
import { MEDIA_SYMBOLS } from "../../di/symbols";

import { getMediaInputSchema } from "../../application/use-cases/get-media.use-case";
import { listMediaInputSchema } from "../../application/use-cases/list-media.use-case";
import { deleteMediaInputSchema } from "../../application/use-cases/delete-media.use-case";

import type { IGetMediaController } from "../../interface-adapters/controllers/get-media.controller";
import type { IListMediaController } from "../../interface-adapters/controllers/list-media.controller";
import type { IDeleteMediaController } from "../../interface-adapters/controllers/delete-media.controller";

import { mediaProcedure } from "./procedures";

export const mediaRouter = router({
  getMedia: mediaProcedure.input(getMediaInputSchema).query(({ input }) => {
    const ctrl = mediaContainer.get<IGetMediaController>(MEDIA_SYMBOLS.IGetMediaController);
    return ctrl(input);
  }),
  listMedia: mediaProcedure.input(listMediaInputSchema).query(({ input }) => {
    const ctrl = mediaContainer.get<IListMediaController>(MEDIA_SYMBOLS.IListMediaController);
    return ctrl(input);
  }),
  deleteMedia: mediaProcedure.input(deleteMediaInputSchema).mutation(({ input }) => {
    const ctrl = mediaContainer.get<IDeleteMediaController>(MEDIA_SYMBOLS.IDeleteMediaController);
    return ctrl(input);
  }),
});

export type MediaRouter = typeof mediaRouter;
