import 'package:equatable/equatable.dart';

enum PtzDirection { none, left, right, up, down, zoomIn, zoomOut }

enum PtzLockStatus { none, acquiring, locked, denied }

class PtzState extends Equatable {
  final int? activeCameraId;
  final PtzDirection currentDirection;
  final bool isMoving;
  final PtzLockStatus lockStatus;
  final String? lockedBy;
  final String? error;

  const PtzState({
    this.activeCameraId,
    this.currentDirection = PtzDirection.none,
    this.isMoving = false,
    this.lockStatus = PtzLockStatus.none,
    this.lockedBy,
    this.error,
  });

  bool get hasActiveCamera => activeCameraId != null;
  bool get hasLock => lockStatus == PtzLockStatus.locked;

  PtzState copyWith({
    int? activeCameraId,
    PtzDirection? currentDirection,
    bool? isMoving,
    PtzLockStatus? lockStatus,
    String? lockedBy,
    String? error,
    bool clearCamera = false,
  }) {
    return PtzState(
      activeCameraId:
          clearCamera ? null : (activeCameraId ?? this.activeCameraId),
      currentDirection: currentDirection ?? this.currentDirection,
      isMoving: isMoving ?? this.isMoving,
      lockStatus: lockStatus ?? this.lockStatus,
      lockedBy: lockedBy ?? this.lockedBy,
      error: error,
    );
  }

  @override
  List<Object?> get props =>
      [activeCameraId, currentDirection, isMoving, lockStatus, lockedBy, error];
}
