Files
gridpilot.gg/adapters/racing/ports/InMemoryDriverExtendedProfileProvider.ts
Marc Mintel 597bb48248
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 4m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped
integration tests
2026-01-22 17:29:06 +01:00

112 lines
5.2 KiB
TypeScript

import type { DriverExtendedProfileProvider } from '@core/racing/application/ports/DriverExtendedProfileProvider';
import type { Logger } from '@core/shared/domain/Logger';
// TODO Provider doesnt exist in Clean Architecture
// TODO Hardcoded data here must be moved to a better place
export class InMemoryDriverExtendedProfileProvider implements DriverExtendedProfileProvider {
constructor(private readonly logger: Logger) {
this.logger.info('InMemoryDriverExtendedProfileProvider initialized.');
}
getExtendedProfile(driverId: string): {
socialHandles: {
platform: 'twitter' | 'youtube' | 'twitch' | 'discord';
handle: string;
url: string;
}[];
achievements: {
id: string;
title: string;
description: string;
icon: 'trophy' | 'medal' | 'star' | 'crown' | 'target' | 'zap';
rarity: 'common' | 'rare' | 'epic' | 'legendary';
earnedAt: string;
}[];
racingStyle: string;
favoriteTrack: string;
favoriteCar: string;
timezone: string;
availableHours: string;
lookingForTeam: boolean;
openToRequests: boolean;
} | null {
this.logger.debug(`[InMemoryDriverExtendedProfileProvider] Getting extended profile for driver: ${driverId}`);
const hash = driverId.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
const socialOptions: {
platform: 'twitter' | 'youtube' | 'twitch' | 'discord';
handle: string;
url: string;
}[][] = [
[
{ platform: 'twitter', handle: '@speedracer', url: 'https://twitter.com/speedracer' },
{ platform: 'youtube', handle: 'SpeedRacer Racing', url: 'https://youtube.com/@speedracer' },
{ platform: 'twitch', handle: 'speedracer_live', url: 'https://twitch.tv/speedracer_live' },
],
[
{ platform: 'twitter', handle: '@racingpro', url: 'https://twitter.com/racingpro' },
{ platform: 'discord', handle: 'RacingPro#1234', url: '#' },
],
[
{ platform: 'twitch', handle: 'simracer_elite', url: 'https://twitch.tv/simracer_elite' },
{ platform: 'youtube', handle: 'SimRacer Elite', url: 'https://youtube.com/@simracerelite' },
],
];
const achievementSets: {
id: string;
title: string;
description: string;
icon: 'trophy' | 'medal' | 'star' | 'crown' | 'target' | 'zap';
rarity: 'common' | 'rare' | 'epic' | 'legendary';
earnedAt: string;
}[][] = [
[
{ id: '1', title: 'First Victory', description: 'Win your first race', icon: 'trophy', rarity: 'common', earnedAt: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000).toISOString() },
{ id: '2', title: 'Clean Racer', description: '10 races without incidents', icon: 'star', rarity: 'rare', earnedAt: new Date(Date.now() - 60 * 24 * 60 * 60 * 1000).toISOString() },
{ id: '3', title: 'Podium Streak', description: '5 consecutive podium finishes', icon: 'medal', rarity: 'epic', earnedAt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString() },
],
[
{ id: '1', title: 'Rookie No More', description: 'Complete 25 races', icon: 'target', rarity: 'common', earnedAt: new Date(Date.now() - 120 * 24 * 60 * 60 * 1000).toISOString() },
{ id: '2', title: 'Consistent Performer', description: 'Maintain 80%+ consistency rating', icon: 'zap', rarity: 'rare', earnedAt: new Date(Date.now() - 45 * 24 * 60 * 60 * 1000).toISOString() },
],
[
{ id: '1', title: 'Welcome Racer', description: 'Join GridPilot', icon: 'star', rarity: 'common', earnedAt: new Date(Date.now() - 180 * 24 * 60 * 60 * 1000).toISOString() },
{ id: '2', title: 'Team Player', description: 'Join a racing team', icon: 'medal', rarity: 'rare', earnedAt: new Date(Date.now() - 80 * 24 * 60 * 60 * 1000).toISOString() },
],
];
const tracks = ['Spa-Francorchamps', 'Nürburgring Nordschleife', 'Suzuka', 'Monza', 'Interlagos', 'Silverstone'];
const cars = ['Porsche 911 GT3 R', 'Ferrari 488 GT3', 'Mercedes-AMG GT3', 'BMW M4 GT3', 'Audi R8 LMS'];
const styles = ['Aggressive Overtaker', 'Consistent Pacer', 'Strategic Calculator', 'Late Braker', 'Smooth Operator'];
const timezones = ['EST (UTC-5)', 'CET (UTC+1)', 'PST (UTC-8)', 'GMT (UTC+0)', 'JST (UTC+9)'];
const hours = ['Evenings (18:00-23:00)', 'Weekends only', 'Late nights (22:00-02:00)', 'Flexible schedule'];
const socialHandles = socialOptions[hash % socialOptions.length] ?? [];
const achievements = achievementSets[hash % achievementSets.length] ?? [];
const racingStyle = styles[hash % styles.length] ?? 'Consistent Pacer';
const favoriteTrack = tracks[hash % tracks.length] ?? 'Unknown Track';
const favoriteCar = cars[hash % cars.length] ?? 'Unknown Car';
const timezone = timezones[hash % timezones.length] ?? 'UTC';
const availableHours = hours[hash % hours.length] ?? 'Flexible schedule';
return {
socialHandles,
achievements,
racingStyle,
favoriteTrack,
favoriteCar,
timezone,
availableHours,
lookingForTeam: hash % 3 === 0,
openToRequests: hash % 2 === 0,
};
}
clear(): void {
this.logger.info('[InMemoryDriverExtendedProfileProvider] Clearing all data');
// No data to clear as this provider generates data on-the-fly
}
}