import { Fields, Fn, OperationParser } from "../types/Anilist.ts" import { UserFavouritesArgs } from "../../graphql-codegen/generated/graphql.ts" import { Favourites } from "./Favourites.ts" import { MediaListOptions } from "./MediaList.ts" import { UserStatisticTypes } from "./UserStatistics.ts" const NotificationOption = ({ operation, level }: Fields) => ({ withEnabled(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "enabled", level }) return this }, withType(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "type", level }) return this }, }) const ListActivityOption = ({ operation, level }: Fields) => ({ withDisabled(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "disabled", level }) return this }, withType(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "type", level }) return this }, }) export const UserPreviousName = ({ operation, level }: Fields) => ({ /** A previous name of the user. */ withName(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "name", level }) return this }, /** When the user first changed from this name. */ withCreatedAt(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "createdAt", level }) return this }, /** When the user most recently changed from this name. */ withUpdatedAt(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "updatedAt", level }) return this }, }) export const UserOptions = ({ operation, level }: Fields) => ({ /** The language the user wants to see media titles in */ withTitleLanguage(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "titleLanguage", level }) return this }, /** Whether the user has enabled viewing of 18+ content */ withDisplayAdultContent(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "displayAdultContent", level }) return this }, /** Whether the user receives notifications when a show they are watching aires */ withAiringNotifications(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "airingNotifications", level }) return this }, /** Profile highlight color (blue, purple, pink, orange, red, green, gray) */ withProfileColor(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "profileColor", level }) return this }, /** Notification options */ withNotificationOptions(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "notificationOptions", level, hasSubField: true }) op.fn(NotificationOption({ operation, level: level + 1 })) return this }, /** The user's timezone offset (Auth user only) */ withTimezone(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "timezone", level }) return this }, /** Minutes between activity for them to be merged together. 0 is Never, Above 2 weeks (20160 mins) is Always. */ withActivityMergeTime(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "activityMergeTime", level }) return this }, /** The language the user wants to see staff and character names in */ withStaffNameLanguage(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "staffNameLanguage", level }) return this }, /** Whether the user only allow messages from users they follow */ withRestrictMessagesToFollowing(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "restrictMessagesToFollowing", level }) return this }, /** The list activity types the user has disabled from being created from list updates */ withDisabledListActivity(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "disabledListActivity", level, hasSubField: true }) op.fn(ListActivityOption({ operation, level: level + 1 })) return this }, }) export const UserAvatar = ({ operation, level }: Fields) => ({ /** The avatar of user at its largest size */ withLarge(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "large", level }) return this }, /** The avatar of user at medium size */ withMedium(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "medium", level }) return this }, }) export const User = ({ operation, level }: Fields) => ({ /** The id of the user */ withId(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "id", level }) return this }, /** The name of the user */ withName(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "name", level }) return this }, /** The bio written by user (Markdown) */ withAbout(op?: { alias?: string; args?: { asHtml: boolean } }) { operation.set({ alias: op?.alias, subField: "about", level, variables: op?.args }) return this }, /** The user's avatar images */ withAvatar(op?: { alias?: string; fn?: Fn }) { operation.set({ alias: op?.alias, subField: "avatar", level, hasSubField: true }) if (op?.fn) op.fn(UserAvatar({ operation, level: level + 1 })) else UserAvatar({ operation, level: level + 1 }).withMedium() return this }, /** The user's banner images */ withBannerImage(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "bannerImage", level }) return this }, /** If the authenticated user if following this user */ withIsFollowing(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "isFollowing", level }) return this }, /** If this user if following the authenticated user */ withIsFollower(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "isFollower", level }) return this }, /** If the user is blocked by the authenticated user */ withIsBlocked(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "isBlocked", level }) return this }, withBans(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "bans", level }) return this }, /* The user's general options */ withOptions(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "options", level, hasSubField: true }) op.fn(UserOptions({ operation, level: level + 1 })) return this }, /* The user's media list options */ withMediaListOptions(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "mediaListOptions", level, hasSubField: true }) op.fn(MediaListOptions({ operation, level: level + 1 })) return this }, /* The users favourites */ withFavourites(op: { alias?: string; args?: UserFavouritesArgs; fn: Fn }) { operation.set({ alias: op.alias, subField: "favourites", level, variables: op?.args, hasSubField: true, }) op.fn(Favourites({ operation, level: level + 1 })) return this }, /* The users anime & manga list statistics */ withStatistics(op: { alias?: string; fn: Fn }) { operation.set({ alias: op.alias, subField: "statistics", level, hasSubField: true }) op.fn(UserStatisticTypes({ operation, level: level + 1 })) return this }, /* The number of unread notifications the user has */ withUnreadNotificationCount(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "unreadNotificationCount", level }) return this }, /* The url for the user page on the AniList website */ withSiteUrl(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "siteUrl", level }) return this }, /* The donation tier of the user */ withDonatorTier(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "donatorTier", level }) return this }, /* Custom donation badge text */ withDonatorBadge(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "donatorBadge", level }) return this }, /* The user's moderator roles if they are a site moderator */ withModeratorRoles(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "moderatorRoles", level }) return this }, /* When the user's account was created. (Does not exist for accounts created before 2020) */ withCreatedAt(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "createdAt", level }) return this }, /* When the user's data was last updated */ withUpdatedAt(op?: { alias?: string }) { operation.set({ alias: op?.alias, subField: "updatedAt", level }) return this }, /* The user's previously used names. */ withPreviousNames(op?: { alias?: string; fn?: Fn }) { operation.set({ alias: op?.alias, subField: "previousNames", level, hasSubField: true }) if (op?.fn) op.fn(UserPreviousName({ operation, level: level + 1 })) else UserPreviousName({ operation, level: level + 1 }).withName() return this }, })