depor_os/lib/services/mock/mock_booking_service.dart

140 lines
4.3 KiB
Dart
Raw Normal View History

2026-03-18 11:47:06 +00:00
import '../../models/booking.dart';
import '../booking_repository.dart';
class MockBookingService implements BookingRepository {
static final _activities = [
const BookingActivity(id: 1, name: 'TENIS'),
const BookingActivity(id: 2, name: 'PÁDEL'),
const BookingActivity(id: 3, name: 'BALONCESTO'),
];
// Grid mock por actividad: activityId → aaData
static const _grids = {
1: _tenisMock,
2: _padelMock,
3: _baloncestoMock,
};
static const _courtsByActivity = {1: 4, 2: 3, 3: 2};
@override
Future<List<BookingActivity>> activities() async => _activities;
@override
Future<BookingGrid> grid({
required int activityId,
required String date,
}) async {
final activity =
_activities.firstWhere((a) => a.id == activityId, orElse: () => _activities.first);
final courts = _courtsByActivity[activityId] ?? 4;
final courtTitles =
List.generate(courts, (i) => (i + 1).toString().padLeft(2, '0'));
final rawRows = _grids[activityId] ?? _tenisMock;
final rows = rawRows.asMap().entries.map((e) {
final i = e.key;
final r = e.value;
return BookingRow(
slotIndex: i,
timeLabel: r[0],
cells: r.skip(1).map((c) => BookingCell(c)).toList(),
);
}).toList();
return BookingGrid(
rows: rows,
courtTitles: courtTitles,
activityName: activity.name,
light: 100,
extra: 150,
celebrations: date.startsWith('18') ? 'Miguel Ángel' : null,
);
}
@override
Future<BookingDetail?> singleBooking({
required int activityId,
required String date,
required int slotIndex,
required int courtIndex,
}) async {
final rawRows = _grids[activityId] ?? _tenisMock;
if (slotIndex >= rawRows.length) return null;
final row = rawRows[slotIndex];
// courtIndex is 1-based, row[0] is the time label
final cellIndex = courtIndex; // row[0]=time, row[1]=court1, ...
if (cellIndex >= row.length) return null;
final cellRaw = row[cellIndex];
if (cellRaw.isEmpty) return null;
final cell = BookingCell(cellRaw);
final courtStr = courtIndex.toString().padLeft(2, '0');
final timeLabel = row[0];
final actName =
_activities.firstWhere((a) => a.id == activityId).name;
return BookingDetail(
id: 1000 + slotIndex * 10 + courtIndex,
memberId: cell.memberId ?? 7,
familyId: cell.familyId ?? 1,
date: date,
paid: cell.isPaid,
ticket: TicketPreview(
concepto: '$actName — Pista $courtStr$timeLabel',
base: 8.26,
iva: 1.74,
total: 10.00,
lines: [
TicketLine(concepto: '1h $actName Pista $courtStr', precio: 10.00),
if (!cell.isPaid)
const TicketLine(concepto: 'Pendiente de cobro', precio: 0),
],
),
);
}
}
// ── Mock data ─────────────────────────────────────────────────────────────────
// Formato: [timeLabel, court1, court2, ...]
// Celda: "" libre | "MMMMM.F+" pagada (verde) | "MMMMM.F-" impagada (roja)
const _tenisMock = [
['0800-0900', '', '', '', ''],
['0900-1000', '00007.1+', '', '00042.1+', ''],
['1000-1100', '00085.1-', '', '00007.1+', '00042.1+'],
['1100-1200', '', '00042.1+', '', ''],
['1200-1300', '', '', '', ''],
['1300-1400', '00007.2+', '', '', '00085.1-'],
['1400-1500', '', '', '', ''],
['1500-1600', '', '', '', ''],
['1600-1700', '00007.1+', '00007.1+', '', ''],
['1700-1800', '00007.1+', '00007.1+', '00042.1-', ''],
['1800-1900', '00007.1+', '00007.1+', '00042.1-', '00085.1-'],
['1900-2000', '00042.1+', '', '', ''],
['2000-2100', '00042.1+', '', '', ''],
['2100-2200', '', '', '', ''],
];
const _padelMock = [
['0900-1000', '', '00007.1+', ''],
['1000-1100', '00042.1+', '', '00085.1-'],
['1100-1200', '', '', ''],
['1200-1300', '00007.1+', '', ''],
['1300-1400', '', '', ''],
['1600-1700', '00042.1-', '', ''],
['1700-1800', '00042.1-', '00007.1+', ''],
['1800-1900', '', '00007.1+', '00042.1+'],
['1900-2000', '', '', '00042.1+'],
['2000-2100', '', '', ''],
];
const _baloncestoMock = [
['1000-1200', '00007.1+', ''],
['1600-1800', '', '00042.1-'],
['1800-2000', '00085.1+', '00085.1+'],
['2000-2200', '', ''],
];