diff --git a/src/lib/types/api/characterSeries.ts b/src/lib/types/api/characterSeries.ts new file mode 100644 index 00000000..41210fa0 --- /dev/null +++ b/src/lib/types/api/characterSeries.ts @@ -0,0 +1,88 @@ +/** + * Character Series Types + * + * Type definitions for character series data from the API. + * CharacterSeries is a database-driven classification system for characters. + * Unlike weapons (one-to-many), characters can belong to multiple series (many-to-many). + * + * @module types/api/characterSeries + */ + +/** + * Embedded series reference on characters. + * This is the structure returned in character.series field (array). + */ +export interface CharacterSeriesRef { + id: string + slug: string + name: { en: string; ja: string } +} + +/** + * Full character series from /api/v1/character_series endpoint. + * characterCount is only included in the :full view (show endpoint). + */ +export interface CharacterSeries { + id: string + name: { en: string; ja: string } + slug: string + order: number + characterCount?: number +} + +/** + * Input type for character series form (client-side) + */ +export interface CharacterSeriesInput { + name_en: string + name_jp: string + slug: string + order: number +} + +/** + * Payload for creating a new character series (editor only) + */ +export interface CreateCharacterSeriesPayload { + name_en: string + name_jp: string + slug: string + order?: number +} + +/** + * Payload for updating an existing character series (editor only) + */ +export interface UpdateCharacterSeriesPayload { + name_en?: string + name_jp?: string + slug?: string + order?: number +} + +/** + * Type guard to check if a series value is the new object format vs legacy integer. + * During migration, some characters may still have integer series values. + * + * @param series - The series value to check + * @returns True if series is a CharacterSeriesRef object + */ +export function isCharacterSeriesRef(series: unknown): series is CharacterSeriesRef { + return ( + series !== null && + typeof series === 'object' && + 'slug' in series && + 'id' in series && + 'name' in series + ) +} + +/** + * Type guard to check if series array contains new object format + * + * @param series - The series array to check + * @returns True if array contains CharacterSeriesRef objects + */ +export function hasCharacterSeriesRefs(series: unknown[]): series is CharacterSeriesRef[] { + return series.length > 0 && isCharacterSeriesRef(series[0]) +} diff --git a/src/lib/types/api/summonSeries.ts b/src/lib/types/api/summonSeries.ts new file mode 100644 index 00000000..bf0a36b0 --- /dev/null +++ b/src/lib/types/api/summonSeries.ts @@ -0,0 +1,76 @@ +/** + * Summon Series Types + * + * Type definitions for summon series data from the API. + * SummonSeries is a database-driven classification system for summons. + * + * @module types/api/summonSeries + */ + +/** + * Embedded series reference on summons. + * This is the structure returned in summon.series field. + */ +export interface SummonSeriesRef { + id: string + slug: string + name: { en: string; ja: string } +} + +/** + * Full summon series from /api/v1/summon_series endpoint. + * summonCount is only included in the :full view (show endpoint). + */ +export interface SummonSeries { + id: string + name: { en: string; ja: string } + slug: string + order: number + summonCount?: number +} + +/** + * Input type for summon series form (client-side) + */ +export interface SummonSeriesInput { + name_en: string + name_jp: string + slug: string + order: number +} + +/** + * Payload for creating a new summon series (editor only) + */ +export interface CreateSummonSeriesPayload { + name_en: string + name_jp: string + slug: string + order?: number +} + +/** + * Payload for updating an existing summon series (editor only) + */ +export interface UpdateSummonSeriesPayload { + name_en?: string + name_jp?: string + slug?: string + order?: number +} + +/** + * Type guard to check if a series value is the new object format. + * + * @param series - The series value to check + * @returns True if series is a SummonSeriesRef object + */ +export function isSummonSeriesRef(series: unknown): series is SummonSeriesRef { + return ( + series !== null && + typeof series === 'object' && + 'slug' in series && + 'id' in series && + 'name' in series + ) +}