/// User types
class UserType {
  static const customer = 'customer';
  static const mitra = 'mitra';
  UserType._();
}

/// Chat session statuses
class SessionStatus {
  static const searching = 'searching';
  static const pendingAcceptance = 'pending_acceptance';
  static const pendingPayment = 'pending_payment';
  static const active = 'active';
  static const extending = 'extending';
  static const closing = 'closing';
  static const completed = 'completed';
  static const cancelled = 'cancelled';
  static const expired = 'expired';
  SessionStatus._();
}

/// Chat message statuses
class MessageStatus {
  static const sent = 'sent';
  static const delivered = 'delivered';
  static const read = 'read';
  MessageStatus._();
}

/// Chat message types
class MessageType {
  static const text = 'text';
  MessageType._();
}

/// Session extension statuses
class ExtensionStatus {
  static const pending = 'pending';
  static const accepted = 'accepted';
  static const rejected = 'rejected';
  static const timeout = 'timeout';
  ExtensionStatus._();
}

/// Chat request notification responses (Phase 3.5).
/// `null` on the wire means "still pending" — no enum value.
enum RequestResponse {
  accepted('accepted'),
  declined('declined'),
  missed('missed'),
  ignored('ignored');

  final String value;
  const RequestResponse(this.value);

  static RequestResponse? fromString(String? v) {
    if (v == null) return null;
    for (final e in values) {
      if (e.value == v) return e;
    }
    return null;
  }
}

/// Session mode — chat or voice call. Mirrors backend `payment_sessions.mode`
/// (added in Phase 4 stage 1). Mitra only reads this to render the header
/// "Voice Call" pill — there is no functional difference from a regular chat.
enum SessionMode {
  chat('chat'),
  call('call');

  final String value;
  const SessionMode(this.value);

  static SessionMode fromString(String? v) =>
      values.firstWhere((e) => e.value == v, orElse: () => SessionMode.chat);
}

/// Session topic sensitivity
enum TopicSensitivity {
  regular('regular'),
  sensitive('sensitive');

  final String value;
  const TopicSensitivity(this.value);

  static TopicSensitivity fromString(String? v) =>
      values.firstWhere((e) => e.value == v, orElse: () => TopicSensitivity.regular);
}

/// Pairing request type — distinguishes general blast from targeted
/// "Curhat lagi" returning-chat requests.
enum PairingRequestType {
  general('general'),
  returning('returning');

  final String value;
  const PairingRequestType(this.value);

  static PairingRequestType fromString(String? v) =>
      values.firstWhere((e) => e.value == v, orElse: () => PairingRequestType.general);
}

/// WebSocket message types
class WsMessage {
  // Auth
  static const auth = 'auth';
  static const authOk = 'auth_ok';
  static const error = 'error';

  // Chat
  static const message = 'message';
  static const messageAck = 'message_ack';
  static const messageStatus = 'message_status';
  static const typing = 'typing';

  // Pairing
  static const chatRequest = 'chat_request';
  static const chatRequestClosed = 'chat_request_closed';
  static const paired = 'paired';

  // Session lifecycle
  static const sessionTimer = 'session_timer';
  static const sessionExpired = 'session_expired';
  static const sessionClosing = 'session_closing';
  static const sessionCompleted = 'session_completed';
  static const sessionPaused = 'session_paused';
  static const sessionResumed = 'session_resumed';
  // Phase 4 — `session_warning` is customer-only; the mitra never receives it.
  // Kept here for symmetry with backend constants only.

  // Extension
  static const extensionRequest = 'extension_request';
  static const extensionResponse = 'extension_response';

  // Topic sensitivity
  static const sessionTopicUpdated = 'session_topic_updated';

  // Delivery
  static const delivered = 'delivered';
  static const read = 'read';

  // Early end
  static const earlyEnd = 'early_end';

  WsMessage._();
}
