MotorSignal-App/lib/services/garage/motorcycle_image_service.dart

111 lines
3.7 KiB
Dart

/// Metadata for a motorcycle photograph or reference image
class MotorcycleImageReference {
final String? assetPath;
final String? networkUrl;
final String? localFilePath;
final String caption;
final String attribution;
final bool isPhoto;
const MotorcycleImageReference({
this.assetPath,
this.networkUrl,
this.localFilePath,
required this.caption,
this.attribution = 'Technical Reference',
this.isPhoto = false,
});
bool get hasImage => assetPath != null || networkUrl != null || localFilePath != null;
}
/// Central extensible repository providing authentic motorcycle reference images
class MotorcycleImageService {
static const MotorcycleImageService _instance = MotorcycleImageService._internal();
factory MotorcycleImageService() => _instance;
const MotorcycleImageService._internal();
/// Known registry mapping (Make + Model + Optional Year) to curated reference images
static final Map<String, MotorcycleImageReference> _registry = {
// 2001 Yamaha YZF-R6 (User's field test vehicle)
'yamaha_yzf-r6_2001': const MotorcycleImageReference(
assetPath: 'assets/images/motorcycles/yamaha_yzf_r6_2001.png',
caption: '2001 Yamaha YZF-R6 (5EB)',
attribution: 'Factory Supersport Reference',
isPhoto: true,
),
'yamaha_r6_2001': const MotorcycleImageReference(
assetPath: 'assets/images/motorcycles/yamaha_yzf_r6_2001.png',
caption: '2001 Yamaha YZF-R6 (5EB)',
attribution: 'Factory Supersport Reference',
isPhoto: true,
),
'yamaha_yzf-r6': const MotorcycleImageReference(
assetPath: 'assets/images/motorcycles/yamaha_yzf_r6_2001.png',
caption: 'Yamaha YZF-R6 Supersport',
attribution: 'Factory Technical Reference',
isPhoto: true,
),
'yamaha_r6': const MotorcycleImageReference(
assetPath: 'assets/images/motorcycles/yamaha_yzf_r6_2001.png',
caption: 'Yamaha YZF-R6 Supersport',
attribution: 'Factory Technical Reference',
isPhoto: true,
),
'yamaha_yzf-r1': const MotorcycleImageReference(
assetPath: 'assets/images/motorcycles/yamaha_r1.png',
caption: 'Yamaha YZF-R1 Superbike',
attribution: 'Crossplane Superbike Reference',
isPhoto: true,
),
'yamaha_mt-09': const MotorcycleImageReference(
assetPath: 'assets/images/motorcycles/yamaha_mt09.png',
caption: 'Yamaha MT-09 Hyper Naked',
attribution: 'CP3 Triple Reference',
isPhoto: true,
),
};
/// Resolves the best available photographic image or reference for a motorcycle
MotorcycleImageReference getReferenceImage({
required String? make,
required String? model,
int? year,
}) {
if (make == null || model == null) {
return const MotorcycleImageReference(caption: 'Generic Motorcycle Reference');
}
final cleanMake = make.trim().toLowerCase();
final cleanModel = model.trim().toLowerCase().replaceAll(' ', '-');
// 1. Exact make_model_year lookup
if (year != null) {
final keyWithYear = '${cleanMake}_${cleanModel}_$year';
if (_registry.containsKey(keyWithYear)) {
return _registry[keyWithYear]!;
}
}
// 2. Exact make_model lookup
final keyNoYear = '${cleanMake}_$cleanModel';
if (_registry.containsKey(keyNoYear)) {
return _registry[keyNoYear]!;
}
// 3. Normalized alias matching (e.g. YZF-R6 -> R6)
final simplifiedModel = cleanModel.replaceAll('yzf-', '');
final keySimplified = '${cleanMake}_$simplifiedModel';
if (_registry.containsKey(keySimplified)) {
return _registry[keySimplified]!;
}
// 4. Default fallback
return MotorcycleImageReference(
caption: '$year $make $model'.trim(),
attribution: 'Schematic Vector',
isPhoto: false,
);
}
}