import { ApiClient } from "./api-client"; import type { AttachImageInputDto, ArticleOutputDto, CategoryOutputDto, CategoryTreeOutputDto, CommentOutputDto, CommentTreeOutputDto, CreateArticleInputDto, CreateCategoryInputDto, CreateCommentInputDto, CreateTagInputDto, DeleteResponseDto, ListArticlesInputDto, ManageArticlesInputDto, PaginatedArticlesOutputDto, PaginatedBookmarksOutputDto, ProfileOutputDto, TagOutputDto, UpdateArticleInputDto, UpdateCategoryInputDto, UpdateMeInputDto, UpdateTagInputDto, UploadedImageOutputDto, UserOutputDto, BookmarkOutputDto, } from "./dtos"; type ApiQuery = Record; export function createTvOneApiServices(api: ApiClient) { return { users: { me: () => api.get("/users/me"), updateMe: (dto: UpdateMeInputDto) => api.patch("/users/me", dto), }, profile: { get: () => api.get("/profile"), }, categories: { tree: () => api.get("/categories"), flat: () => api.get("/categories/flat"), create: (dto: CreateCategoryInputDto) => api.post("/categories", dto), update: (id: string, dto: UpdateCategoryInputDto) => api.patch(`/categories/${id}`, dto), remove: (id: string) => api.delete(`/categories/${id}`), }, tags: { list: () => api.get("/tags"), create: (dto: CreateTagInputDto) => api.post("/tags", dto), update: (id: string, dto: UpdateTagInputDto) => api.patch(`/tags/${id}`, dto), remove: (id: string) => api.delete(`/tags/${id}`), }, articles: { listPublished: (query?: ListArticlesInputDto) => api.get("/articles", query as ApiQuery | undefined), findPublishedBySlug: (slug: string) => api.get(`/articles/by-slug/${slug}`), listManage: (query?: ManageArticlesInputDto) => api.get("/articles/manage", query as ApiQuery | undefined), findById: (id: string) => api.get(`/articles/by-id/${id}`), create: (dto: CreateArticleInputDto) => api.post("/articles", dto), update: (id: string, dto: UpdateArticleInputDto) => api.patch(`/articles/${id}`, dto), remove: (id: string) => api.delete(`/articles/${id}`), attachImage: (id: string, dto: AttachImageInputDto) => api.post(`/articles/${id}/images`, dto), }, comments: { listForArticle: (articleId: string) => api.get(`/comments/article/${articleId}`), create: (articleId: string, dto: CreateCommentInputDto) => api.post(`/comments/article/${articleId}`, dto), remove: (id: string) => api.delete(`/comments/${id}`), }, bookmarks: { listMine: (query?: { page?: number; limit?: number }) => api.get("/bookmarks/me", query), add: (articleId: string) => api.post(`/bookmarks/${articleId}`), remove: (articleId: string) => api.delete(`/bookmarks/${articleId}`), }, images: { upload: async (file: File) => { const form = new FormData(); form.append("file", file); return api.post("/images/upload", form, { isFormData: true, }); }, }, }; }