import { ViewModel } from "../contracts/view-models/ViewModel"; import { AdminUserViewModel } from "./AdminUserViewModel"; import type { AdminUserViewData } from '@/lib/view-data/AdminUserViewData'; /** * UserListViewModel * * View Model for user list with pagination and filtering state. */ export class UserListViewModel extends ViewModel { users: AdminUserViewModel[]; total: number; page: number; limit: number; totalPages: number; // UI-specific derived fields (primitive outputs only) readonly hasUsers: boolean; readonly showPagination: boolean; readonly startIndex: number; readonly endIndex: number; constructor(data: { users: AdminUserViewData[]; total: number; page: number; limit: number; totalPages: number; }) { super(); this.users = data.users.map(viewData => new AdminUserViewModel(viewData)); this.total = data.total; this.page = data.page; this.limit = data.limit; this.totalPages = data.totalPages; // Derive UI state this.hasUsers = this.users.length > 0; this.showPagination = this.totalPages > 1; this.startIndex = this.users.length > 0 ? (this.page - 1) * this.limit + 1 : 0; this.endIndex = this.users.length > 0 ? (this.page - 1) * this.limit + this.users.length : 0; } }