// ABOUTME: This file defines security events for the security BLoC pattern
// ABOUTME: Includes authentication, key generation, and security configuration events

import 'package:equatable/equatable.dart';
import '../../models/security/auth_method.dart';
import '../../models/security/security_settings.dart';

/// Base class for all security events
abstract class SecurityEvent extends Equatable {
  const SecurityEvent();

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

/// Event to initialize the security system
class SecurityInitializeEvent extends SecurityEvent {
  const SecurityInitializeEvent();
}

/// Event to check current security status
class SecurityCheckStatusEvent extends SecurityEvent {
  const SecurityCheckStatusEvent();
}

/// Event to authenticate user
class SecurityAuthenticateEvent extends SecurityEvent {
  final String? password;
  final bool useBiometric;

  const SecurityAuthenticateEvent({
    this.password,
    this.useBiometric = false,
  });

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

/// Event to logout/end session
class SecurityLogoutEvent extends SecurityEvent {
  const SecurityLogoutEvent();
}

/// Event to set up password authentication
class SecuritySetupPasswordEvent extends SecurityEvent {
  final String password;
  final String confirmPassword;

  const SecuritySetupPasswordEvent({
    required this.password,
    required this.confirmPassword,
  });

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

/// Event to set up biometric authentication
class SecuritySetupBiometricEvent extends SecurityEvent {
  final bool withPasswordFallback;

  const SecuritySetupBiometricEvent({
    this.withPasswordFallback = true,
  });

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

/// Event to change authentication method
class SecurityChangeAuthMethodEvent extends SecurityEvent {
  final AuthMethod newMethod;
  final String? password;

  const SecurityChangeAuthMethodEvent({
    required this.newMethod,
    this.password,
  });

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

/// Event to generate new encryption keys
class SecurityGenerateKeysEvent extends SecurityEvent {
  final int keySize;
  final bool forceRegenerate;

  const SecurityGenerateKeysEvent({
    this.keySize = 2048,
    this.forceRegenerate = false,
  });

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

/// Event to rotate encryption keys
class SecurityRotateKeysEvent extends SecurityEvent {
  const SecurityRotateKeysEvent();
}

/// Event to enable/disable local encryption
class SecurityToggleEncryptionEvent extends SecurityEvent {
  final bool enable;
  final String? password;

  const SecurityToggleEncryptionEvent({
    required this.enable,
    this.password,
  });

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

/// Event to update security settings
class SecurityUpdateSettingsEvent extends SecurityEvent {
  final SecuritySettings settings;

  const SecurityUpdateSettingsEvent({
    required this.settings,
  });

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

/// Event to check biometric availability
class SecurityCheckBiometricEvent extends SecurityEvent {
  const SecurityCheckBiometricEvent();
}

/// Event to validate key integrity
class SecurityValidateKeysEvent extends SecurityEvent {
  const SecurityValidateKeysEvent();
}

/// Event to extend current session
class SecurityExtendSessionEvent extends SecurityEvent {
  const SecurityExtendSessionEvent();
}

/// Event to change password
class SecurityChangePasswordEvent extends SecurityEvent {
  final String currentPassword;
  final String newPassword;
  final String confirmPassword;

  const SecurityChangePasswordEvent({
    required this.currentPassword,
    required this.newPassword,
    required this.confirmPassword,
  });

  @override
  List<Object?> get props => [currentPassword, newPassword, confirmPassword];
}

/// Event to reset security configuration
class SecurityResetEvent extends SecurityEvent {
  final String? confirmationCode;

  const SecurityResetEvent({
    this.confirmationCode,
  });

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

/// Event to backup security data
class SecurityBackupEvent extends SecurityEvent {
  final String password;

  const SecurityBackupEvent({
    required this.password,
  });

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

/// Event to restore security data
class SecurityRestoreEvent extends SecurityEvent {
  final Map<String, dynamic> backupData;
  final String password;

  const SecurityRestoreEvent({
    required this.backupData,
    required this.password,
  });

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

/// Event to update security policies
class SecurityUpdatePoliciesEvent extends SecurityEvent {
  final SecurityPolicies policies;

  const SecurityUpdatePoliciesEvent({
    required this.policies,
  });

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

/// Event to perform security maintenance
class SecurityMaintenanceEvent extends SecurityEvent {
  final List<String> tasks;

  const SecurityMaintenanceEvent({
    required this.tasks,
  });

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

/// Event to handle authentication failure
class SecurityAuthFailureEvent extends SecurityEvent {
  final String error;
  final AuthMethod method;

  const SecurityAuthFailureEvent({
    required this.error,
    required this.method,
  });

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

/// Event to handle session timeout
class SecuritySessionTimeoutEvent extends SecurityEvent {
  const SecuritySessionTimeoutEvent();
}

/// Event to record security audit log
class SecurityAuditLogEvent extends SecurityEvent {
  final String action;
  final Map<String, dynamic>? metadata;

  const SecurityAuditLogEvent({
    required this.action,
    this.metadata,
  });

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