import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_config.dart';

class BookableSpacemodel {
  String spaceUuid;
  String spaceName;
  BookableSpaceConfig? spaceConfig;
  String spaceVirtualAddress;

  BookableSpacemodel({
    required this.spaceUuid,
    required this.spaceName,
    this.spaceConfig,
    required this.spaceVirtualAddress,
  });
  factory BookableSpacemodel.zero() => BookableSpacemodel(
        spaceUuid: '',
        spaceName: '',
        spaceVirtualAddress: '',
      );
  factory BookableSpacemodel.fromJson(Map<String, dynamic> json) =>
      BookableSpacemodel(
        spaceUuid: json['uuid'] as String,
        spaceName: json['spaceName'] as String,
        spaceConfig: json['bookableConfig'] == null
            ? BookableSpaceConfig.zero()
            : BookableSpaceConfig.fromJson(
                json['bookableConfig'] as Map<String, dynamic>),
        spaceVirtualAddress: json['virtualLocation'] as String,
      );

  static List<BookableSpacemodel> fromJsonList(List<dynamic> jsonList) =>
      jsonList
          .map(
            (e) => BookableSpacemodel.fromJson(e as Map<String, dynamic>),
          )
          .toList();

  bool get isValid =>
      spaceUuid.isNotEmpty &&
      spaceName.isNotEmpty &&
      spaceVirtualAddress.isNotEmpty &&
      spaceConfig != null &&
      spaceConfig!.isValid;
}
