import type { CreatePlaylistRequest, ReorderPlaylistRequest, UpdatePlaylistRequest, } from "../../shared/playlist.ts"; import { VALIDATION } from "../../shared/validation.ts"; export function isCreatePlaylistRequest( obj: unknown, ): obj is CreatePlaylistRequest { if ( !obj || typeof obj !== "object" || !("title" in obj) || typeof obj.title !== "string" || !("isPublic" in obj) || typeof obj.isPublic !== "boolean" ) return false; const o = obj as Record; if ( (o.title as string).length === 0 || (o.title as string).length > VALIDATION.PLAYLIST_TITLE_MAX ) return false; if ( "description" in o && typeof o.description !== "string" && o.description !== null ) return false; if ( typeof o.description === "string" && (o.description as string).length > VALIDATION.PLAYLIST_DESCRIPTION_MAX ) return false; return true; } export function isUpdatePlaylistRequest( obj: unknown, ): obj is UpdatePlaylistRequest { if (!obj || typeof obj !== "object") return false; const o = obj as Record; if ("title" in o) { if (typeof o.title !== "string") return false; if ( (o.title as string).length === 0 || (o.title as string).length > VALIDATION.PLAYLIST_TITLE_MAX ) return false; } if ( "description" in o && typeof o.description !== "string" && o.description !== null ) return false; if ( typeof o.description === "string" && (o.description as string).length > VALIDATION.PLAYLIST_DESCRIPTION_MAX ) return false; if ("isPublic" in o && typeof o.isPublic !== "boolean") return false; return true; } export function isReorderPlaylistRequest( obj: unknown, ): obj is ReorderPlaylistRequest { return !!obj && typeof obj === "object" && "dumpIds" in obj && Array.isArray(obj.dumpIds) && (obj.dumpIds as unknown[]).every((id) => typeof id === "string"); }