/// Format a remaining-seconds countdown for display in a button or label.
/// - Under 90 seconds: "Xd"   (e.g. "60d")
/// - 90 seconds and up:  "Xm Yd" (e.g. "11m 40d")
/// `d` and `m` are Indonesian short forms for detik (second) and menit (minute).
String formatCountdown(int totalSeconds) {
  if (totalSeconds < 90) return '${totalSeconds}d';
  final minutes = totalSeconds ~/ 60;
  final seconds = totalSeconds % 60;
  return '${minutes}m ${seconds}d';
}

/// 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._();
}

/// 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);
}

/// 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';

  // 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._();
}
