import { Fields, Fn, OperationParser } from "../types/Anilist.ts" import { Media } from "./Media.ts" import { FuzzyDate } from "../anilist.ts" import { User } from "./User.ts" import { MediaListScoreArgs } from "../../graphql-codegen/generated/graphql.ts" export const MediaListTypeOptions = ({ operation, level }: Fields) => ({ /** The order each list should be displayed in */ withSectionOrder(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "sectionOrder", level }) return this }, /** If the completed sections of the list should be separated by format */ withSplitCompletedSectionByFormat(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "splitCompletedSectionByFormat", level }) return this }, /** The names of the user's custom lists */ withCustomLists(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "customLists", level }) return this }, /** The names of the user's advanced scoring sections */ withAdvancedScoring(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "advancedScoring", level }) return this }, /** If advanced scoring is enabled */ withAdvancedScoringEnabled(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "advancedScoringEnabled", level }) return this }, }) export const MediaListOptions = ({ operation, level }: Fields) => ({ /** The score format the user is using for media lists */ withScoreFormat(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "scoreFormat", level }) return this }, /** The default order list rows should be displayed in */ withRowOrder(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "rowOrder", level }) return this }, /** The user's anime list options */ withAnimeList(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "animeList", level, hasSubField: true }) op.fn(MediaListTypeOptions({ operation, level: level + 1 })) return this }, /** The user's manga list options */ withMangaList(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "mangaList", level, hasSubField: true }) op.fn(MediaListTypeOptions({ operation, level: level + 1 })) return this }, }) export const MediaList = ({ operation, level }: Fields) => ({ withCompletedAt(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "completedAt", level, hasSubField: true }) op.fn(FuzzyDate({ operation, level: level + 1 })) return this }, withStartedAt(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "startedAt", level, hasSubField: true }) op.fn(FuzzyDate({ operation, level: level + 1 })) return this }, withId(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "id", level }) return this }, withUserId(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "userId", level }) return this }, withMediaId(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "mediaId", level }) return this }, withScore(op?: { alias?: string; args?: MediaListScoreArgs }) { operation.set({ alias: op?.alias, subField: "score", level, variables: op?.args }) return this }, withStatus(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "status", level }) return this }, withProgress(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "progress", level }) return this }, withProgressVolumes(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "progressVolumes", level }) return this }, withRepeat(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "repeat", level }) return this }, withPriority(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "priority", level }) return this }, withPrivate(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "private", level }) return this }, withNotes(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "notes", level }) return this }, withAdvancedScores(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "advancedScores", level }) return this }, withHiddenFromStatusLists(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "hiddenFromStatusLists", level }) return this }, withUpdatedAt(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "updatedAt", level }) return this }, withCreatedAt(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "createdAt", level }) return this }, withMedia(op?: { alias?: string; fn?: Fn }) { operation.set({ alias: op?.alias, subField: "media", level, hasSubField: true }) if (op?.fn) op.fn(Media({ operation, level: level + 1 })) else Media({ operation, level: level + 1 }).withId() return this }, withUser(op?: { alias?: string; fn?: Fn }) { operation.set({ alias: op?.alias, subField: "user", level, hasSubField: true }) if (op?.fn) op.fn(User({ operation, level: level + 1 })) else User({ operation, level: level + 1 }).withId() return this }, })