/** * TeamDetailsPresenter - Pure data transformer * Transforms API response to view model without DI dependencies. */ import { apiClient, type TeamDetailsViewModel as ApiTeamDetailsViewModel } from '@/lib/apiClient'; export interface TeamMembershipViewModel { role: string; joinedAt: string; isActive: boolean; } export interface TeamInfoViewModel { id: string; name: string; tag?: string | undefined; description?: string | undefined; ownerId: string; leagues?: string[] | undefined; createdAt: string; } export interface TeamDetailsViewModel { team: TeamInfoViewModel; membership: TeamMembershipViewModel | null; canManage: boolean; } export interface ITeamDetailsPresenter { reset(): void; getViewModel(): TeamDetailsViewModel | null; } /** * Transform API response to view model */ function transformApiResponse(apiResponse: ApiTeamDetailsViewModel): TeamDetailsViewModel { return { team: { id: apiResponse.id, name: apiResponse.name, description: apiResponse.description, ownerId: apiResponse.ownerId, createdAt: new Date().toISOString(), // Would need from API }, membership: null, // Would need from API based on current user canManage: false, // Would need from API based on current user }; } export class TeamDetailsPresenter implements ITeamDetailsPresenter { private viewModel: TeamDetailsViewModel | null = null; reset(): void { this.viewModel = null; } async fetchAndPresent(teamId: string): Promise { const apiResponse = await apiClient.teams.getDetails(teamId); if (apiResponse) { this.viewModel = transformApiResponse(apiResponse); } else { this.viewModel = null; } } getViewModel(): TeamDetailsViewModel | null { return this.viewModel; } } /** * Convenience function to fetch and transform team details */ export async function fetchTeamDetails(teamId: string): Promise { const apiResponse = await apiClient.teams.getDetails(teamId); if (!apiResponse) { return null; } return transformApiResponse(apiResponse); }