import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
import 'package:uuid/uuid.dart';

class SubspaceTemplateModel {
  final String? uuid;
  String subspaceName;
  final bool disabled;
  List<Tag>? tags;
  String internalId;

  SubspaceTemplateModel({
    this.uuid,
    required this.subspaceName,
    required this.disabled,
    this.tags,
    String? internalId,
  }) : internalId = internalId ?? const Uuid().v4();

  factory SubspaceTemplateModel.fromJson(Map<String, dynamic> json) {
    final String internalId = json['internalId'] ?? const Uuid().v4();

    return SubspaceTemplateModel(
      uuid: json['uuid'],
      subspaceName: json['subspaceName'] ?? '',
      internalId: internalId,
      disabled: json['disabled'] ?? false,
      tags: (json['tags'] as List<dynamic>?)
              ?.map((item) => Tag.fromJson(item))
              .toList() ??
          [],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'uuid': uuid,
      'subspaceName': subspaceName,
      'disabled': disabled,
      'tags': tags?.map((e) => e.toJson()).toList() ?? [],
    };
  }

  SubspaceTemplateModel copyWith({
    String? uuid,
    String? subspaceName,
    bool? disabled,
    List<Tag>? tags,
    String? internalId,
  }) {
    return SubspaceTemplateModel(
      uuid: uuid ?? this.uuid,
      subspaceName: subspaceName ?? this.subspaceName,
      disabled: disabled ?? this.disabled,
      tags: tags ?? this.tags,
      internalId: internalId ?? this.internalId,
    );
  }
}
