enum TripStatus {
  planned,
  active,
  finished,
  archived,
}

class Trip {
  final String id;
  final String name;
  final int? startTimeUtc;
  final int? finishTimeUtc;
  final int createdAtUtc;
  final TripStatus status;
  final String ownerParticipantId;
  final String? shareCode;
  final String? timezoneId;
  final String? coverPhotoId;
  final String? password;

  Trip({
    required this.id,
    required this.name,
    this.startTimeUtc,
    this.finishTimeUtc,
    required this.createdAtUtc,
    required this.status,
    required this.ownerParticipantId,
    this.shareCode,
    this.timezoneId,
    this.coverPhotoId,
    this.password,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'startTimeUtc': startTimeUtc,
      'finishTimeUtc': finishTimeUtc,
      'createdAtUtc': createdAtUtc,
      'status': status.name,
      'ownerParticipantId': ownerParticipantId,
      'shareCode': shareCode,
      'timezoneId': timezoneId,
      'coverPhotoId': coverPhotoId,
      'password': password,
    };
  }

  factory Trip.fromMap(Map<String, dynamic> map) {
    return Trip(
      id: map['id'] as String,
      name: map['name'] as String,
      startTimeUtc: map['startTimeUtc'] as int?,
      finishTimeUtc: map['finishTimeUtc'] as int?,
      createdAtUtc: map['createdAtUtc'] as int,
      status: TripStatus.values.byName(map['status'] as String),
      ownerParticipantId: map['ownerParticipantId'] as String,
      shareCode: map['shareCode'] as String?,
      timezoneId: map['timezoneId'] as String?,
      coverPhotoId: map['coverPhotoId'] as String?,
      password: map['password'] as String?,
    );
  }
}
