import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart'; // Import for Offset

abstract class SpaceManagementEvent extends Equatable {
  const SpaceManagementEvent();

  @override
  List<Object?> get props => [];
}

class LoadCommunityAndSpacesEvent extends SpaceManagementEvent {
  final BuildContext context;

  const LoadCommunityAndSpacesEvent(this.context);
  @override
  List<Object?> get props => [context];
}

class DeleteCommunityEvent extends SpaceManagementEvent {
  final String communityUuid;

  const DeleteCommunityEvent({
    required this.communityUuid,
  });

  @override
  List<Object> get props => [communityUuid];
}

class CreateSpaceEvent extends SpaceManagementEvent {
  final String name;
  final String icon;
  final Offset position;
  final int? parentIndex;
  final String? direction;

  const CreateSpaceEvent({
    required this.name,
    required this.icon,
    required this.position,
    this.parentIndex,
    this.direction,
  });

  @override
  List<Object> get props => [
        name,
        icon,
        position,
        parentIndex ?? -1, // Use a fallback value if nullable
        direction ?? '', // Use a fallback value if nullable
      ];
}

class SaveSpacesEvent extends SpaceManagementEvent {
  final List<SpaceModel> spaces;
  final String communityUuid;
  final BuildContext context;

  const SaveSpacesEvent(
    this.context, {
    required this.spaces,
    required this.communityUuid,
  });

  @override
  List<Object> get props => [spaces, communityUuid, context];
}

class UpdateSpacePositionEvent extends SpaceManagementEvent {
  final int index;
  final Offset newPosition;

  const UpdateSpacePositionEvent(this.index, this.newPosition);

  @override
  List<Object> get props => [index, newPosition];
}

class CreateCommunityEvent extends SpaceManagementEvent {
  final String name;
  final String description;
  final BuildContext context;

  const CreateCommunityEvent(this.name, this.description, this.context);

  @override
  List<Object?> get props => [name, description, context];
}

class UpdateCommunityEvent extends SpaceManagementEvent {
  final String communityUuid;
  final String name;

  const UpdateCommunityEvent({
    required this.communityUuid,
    required this.name,
  });

  @override
  List<Object> get props => [communityUuid, name];
}

class SelectCommunityEvent extends SpaceManagementEvent {
  final CommunityModel? selectedCommunity;

  const SelectCommunityEvent({
    required this.selectedCommunity,
  });

  @override
  List<Object> get props => [];
}

class NewCommunityEvent extends SpaceManagementEvent {
  final List<CommunityModel> communities;

  const NewCommunityEvent({required this.communities});

  @override
  List<Object> get props => [communities];
}

class SelectSpaceEvent extends SpaceManagementEvent {
  final CommunityModel? selectedCommunity;
  final SpaceModel? selectedSpace;

  const SelectSpaceEvent({
    required this.selectedCommunity,
    required this.selectedSpace,
  });

  @override
  List<Object> get props => [];
}

class FetchProductsEvent extends SpaceManagementEvent {}

class LoadSpaceHierarchyEvent extends SpaceManagementEvent {
  final String communityId;

  const LoadSpaceHierarchyEvent({required this.communityId});

  @override
  List<Object> get props => [communityId];
}

class BlankStateEvent extends SpaceManagementEvent {
  final BuildContext context;

  const BlankStateEvent(this.context);
  @override
  List<Object?> get props => [context];
}

class SpaceModelLoadEvent extends SpaceManagementEvent {
  final BuildContext context;

  const SpaceModelLoadEvent(this.context);
  @override
  List<Object?> get props => [context];
}

class UpdateSpaceModelCache extends SpaceManagementEvent {
  final SpaceTemplateModel updatedModel;
  UpdateSpaceModelCache(this.updatedModel);
}

class DeleteSpaceModelFromCache extends SpaceManagementEvent {
  final String deletedUuid;
  DeleteSpaceModelFromCache(this.deletedUuid);
}
