105 lines
3.0 KiB
Dart
105 lines
3.0 KiB
Dart
// lib/features/events/models/event_models.dart
|
|
class EventTypeModel {
|
|
final int id;
|
|
final String name;
|
|
final String? iconUrl;
|
|
|
|
EventTypeModel({required this.id, required this.name, this.iconUrl});
|
|
|
|
factory EventTypeModel.fromJson(Map<String, dynamic> j) {
|
|
return EventTypeModel(
|
|
id: j['id'] as int,
|
|
name: (j['event_type'] ?? j['name'] ?? '') as String,
|
|
iconUrl: (j['event_type_icon'] ?? j['icon_url']) as String?,
|
|
);
|
|
}
|
|
}
|
|
|
|
class EventImageModel {
|
|
final bool isPrimary;
|
|
final String image;
|
|
|
|
EventImageModel({required this.isPrimary, required this.image});
|
|
|
|
factory EventImageModel.fromJson(Map<String, dynamic> j) {
|
|
return EventImageModel(
|
|
isPrimary: j['is_primary'] == true,
|
|
image: (j['image'] ?? '') as String,
|
|
);
|
|
}
|
|
}
|
|
|
|
class EventModel {
|
|
final int id;
|
|
final String name;
|
|
final String? title;
|
|
final String? description;
|
|
final String startDate; // YYYY-MM-DD
|
|
final String endDate;
|
|
final String? startTime;
|
|
final String? endTime;
|
|
final String? pincode;
|
|
final String? place;
|
|
final bool isBookable;
|
|
final int? eventTypeId;
|
|
final String? thumbImg;
|
|
final List<EventImageModel> images;
|
|
|
|
// NEW fields mapped from backend
|
|
final String? importantInformation;
|
|
final String? venueName;
|
|
final String? eventStatus;
|
|
final String? cancelledReason;
|
|
|
|
EventModel({
|
|
required this.id,
|
|
required this.name,
|
|
this.title,
|
|
this.description,
|
|
required this.startDate,
|
|
required this.endDate,
|
|
this.startTime,
|
|
this.endTime,
|
|
this.pincode,
|
|
this.place,
|
|
this.isBookable = true,
|
|
this.eventTypeId,
|
|
this.thumbImg,
|
|
this.images = const [],
|
|
this.importantInformation,
|
|
this.venueName,
|
|
this.eventStatus,
|
|
this.cancelledReason,
|
|
});
|
|
|
|
factory EventModel.fromJson(Map<String, dynamic> j) {
|
|
final imgs = <EventImageModel>[];
|
|
if (j['images'] is List) {
|
|
for (final im in j['images']) {
|
|
if (im is Map<String, dynamic>) imgs.add(EventImageModel.fromJson(im));
|
|
}
|
|
}
|
|
|
|
return EventModel(
|
|
id: j['id'] is int ? j['id'] as int : int.parse(j['id'].toString()),
|
|
name: (j['name'] ?? '') as String,
|
|
title: j['title'] as String?,
|
|
description: j['description'] as String?,
|
|
startDate: (j['start_date'] ?? '') as String,
|
|
endDate: (j['end_date'] ?? '') as String,
|
|
startTime: j['start_time'] as String?,
|
|
endTime: j['end_time'] as String?,
|
|
pincode: j['pincode'] as String?,
|
|
place: (j['place'] ?? j['venue_name']) as String?,
|
|
isBookable: j['is_bookable'] == null ? true : (j['is_bookable'] == true || j['is_bookable'].toString().toLowerCase() == 'true'),
|
|
eventTypeId: j['event_type'] is int ? j['event_type'] as int : (j['event_type'] != null ? int.tryParse(j['event_type'].toString()) : null),
|
|
thumbImg: j['thumb_img'] as String?,
|
|
images: imgs,
|
|
importantInformation: j['important_information'] as String?,
|
|
venueName: j['venue_name'] as String?,
|
|
eventStatus: j['event_status'] as String?,
|
|
cancelledReason: j['cancelled_reason'] as String?,
|
|
);
|
|
}
|
|
}
|