import { Repository, RepositoryDto, RepositoryEntity } from '$lib/server/models/repository.js'; export class RepositoryMapper { static fromEntity(entity: RepositoryEntity): Repository { return new Repository({ id: entity.id, title: entity.title, description: entity.description, source: entity.source, sourceUrl: entity.source_url, branch: entity.branch, state: entity.state, totalSnippets: entity.total_snippets ?? 0, totalTokens: entity.total_tokens ?? 0, trustScore: entity.trust_score ?? 0, benchmarkScore: entity.benchmark_score ?? 0, stars: entity.stars, githubToken: entity.github_token, lastIndexedAt: entity.last_indexed_at != null ? new Date(entity.last_indexed_at * 1000) : null, createdAt: new Date(entity.created_at * 1000), updatedAt: new Date(entity.updated_at * 1000) }); } static toEntity(domain: Repository): RepositoryEntity { return new RepositoryEntity({ id: domain.id, title: domain.title, description: domain.description, source: domain.source, source_url: domain.sourceUrl, branch: domain.branch, state: domain.state, total_snippets: domain.totalSnippets, total_tokens: domain.totalTokens, trust_score: domain.trustScore, benchmark_score: domain.benchmarkScore, stars: domain.stars, github_token: domain.githubToken, last_indexed_at: domain.lastIndexedAt != null ? Math.floor(domain.lastIndexedAt.getTime() / 1000) : null, created_at: Math.floor(domain.createdAt.getTime() / 1000), updated_at: Math.floor(domain.updatedAt.getTime() / 1000) }); } static toDto(domain: Repository): RepositoryDto { return new RepositoryDto({ id: domain.id, title: domain.title, description: domain.description, source: domain.source, sourceUrl: domain.sourceUrl, branch: domain.branch, state: domain.state, totalSnippets: domain.totalSnippets, totalTokens: domain.totalTokens, trustScore: domain.trustScore, benchmarkScore: domain.benchmarkScore, stars: domain.stars, lastIndexedAt: domain.lastIndexedAt, createdAt: domain.createdAt, updatedAt: domain.updatedAt }); } }