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

import { blogContainer } from "../../di/container";
import { BLOG_SYMBOLS } from "../../di/symbols";

import { getArticlesInputSchema } from "../../application/use-cases/get-articles.use-case";
import { createArticleInputSchema } from "../../application/use-cases/create-article.use-case";
import { getArticleBySlugInputSchema } from "../../application/use-cases/get-article-by-slug.use-case";

import type { IGetArticlesController } from "../../interface-adapters/controllers/get-articles.controller";
import type { ICreateArticleController } from "../../interface-adapters/controllers/create-article.controller";
import type { IGetArticleBySlugController } from "../../interface-adapters/controllers/get-article-by-slug.controller";

import { blogProcedure } from "./procedures";

export const blogRouter = router({
  articleBySlug: blogProcedure
    .input(getArticleBySlugInputSchema)
    .query(({ input }) => {
      const ctrl = blogContainer.get<IGetArticleBySlugController>(
        BLOG_SYMBOLS.IGetArticleBySlugController,
      );
      return ctrl(input);
    }),

  listArticles: blogProcedure
    .input(getArticlesInputSchema)
    .query(({ input }) => {
      const ctrl = blogContainer.get<IGetArticlesController>(
        BLOG_SYMBOLS.IGetArticlesController,
      );
      return ctrl(input);
    }),

  createArticle: blogProcedure
    .input(createArticleInputSchema)
    .mutation(({ input }) => {
      const ctrl = blogContainer.get<ICreateArticleController>(
        BLOG_SYMBOLS.ICreateArticleController,
      );
      return ctrl(input);
    }),
});

export type BlogRouter = typeof blogRouter;
