import 'package:equatable/equatable.dart';

class Organization extends Equatable {
  final String id;
  final String name;
  final String slug;
  final DateTime createdAt;

  const Organization({
    required this.id,
    required this.name,
    required this.slug,
    required this.createdAt,
  });

  @override
  List<Object?> get props => [id, name, slug, createdAt];

  factory Organization.fromJson(Map<String, dynamic> json) {
    return Organization(
      id: json['id'],
      name: json['name'],
      slug: json['slug'],
      createdAt: DateTime.parse(json['createdAt']),
    );
  }
}

class Activity extends Equatable {
  final String id;
  final String userId;
  final String orgId;
  final String? fileId;
  final String action;
  final Map<String, dynamic> metadata;
  final DateTime timestamp;

  const Activity({
    required this.id,
    required this.userId,
    required this.orgId,
    this.fileId,
    required this.action,
    required this.metadata,
    required this.timestamp,
  });

  @override
  List<Object?> get props => [
    id,
    userId,
    orgId,
    fileId,
    action,
    metadata,
    timestamp,
  ];

  factory Activity.fromJson(Map<String, dynamic> json) {
    return Activity(
      id: json['id'],
      userId: json['userId'],
      orgId: json['orgId'],
      fileId: json['fileId'],
      action: json['action'],
      metadata: json['metadata'] ?? {},
      timestamp: DateTime.parse(json['timestamp']),
    );
  }
}

abstract class OrganizationState extends Equatable {
  const OrganizationState();

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

class OrganizationInitial extends OrganizationState {}

class OrganizationLoading extends OrganizationState {}

class OrganizationLoaded extends OrganizationState {
  final List<Organization> organizations;
  final Organization? selectedOrg;
  final bool isLoading;
  final String? error;

  const OrganizationLoaded({
    required this.organizations,
    this.selectedOrg,
    this.isLoading = false,
    this.error,
  });

  @override
  List<Object> get props => [
    organizations,
    selectedOrg ?? '',
    isLoading,
    error ?? '',
  ];
}

class OrganizationError extends OrganizationState {
  final String error;

  const OrganizationError(this.error);

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