@startuml
left to right direction
skinparam packageStyle rectangle
skinparam rectangle {
    BackgroundColor<<actor>> LightGray
    BorderColor Black
}

' ==========================================
' AKTOR UTAMA (Kiri)
' ==========================================
actor "Tunanetra\n(ROLE_USER)" as User
actor "Pendamping\n(ROLE_GUARDIAN)" as Guardian

' ==========================================
' BATAS SISTEM (Tengah)
' ==========================================
rectangle "WalkGuide System" {

    ' --- AUTH ---
    usecase "Hubungkan ke Server" as UC_Server
    usecase "Daftar Akun" as UC_Register
    usecase "Masuk Sistem (Login)" as UC_Login
    usecase "Logout" as UC_Logout
    usecase "Validasi & Refresh JWT" as UC_JWT
    usecase "RBAC Role Routing" as UC_RBAC

    ' --- PAIRING ---
    usecase "Kirim Undangan Pairing" as UC_Invite
    usecase "Terima / Tolak Pairing" as UC_PairingResponse
    usecase "Putus Pairing (Unpair)" as UC_Unpair

    ' --- WALKGUIDE CORE ---
    usecase "Aktifkan Walk Guide Mode" as UC_Walk
    usecase "Deteksi Obstacle\nReal-time (YOLO)" as UC_Detect
    usecase "Analisa Arah & Jarak\nObstacle" as UC_Analyze
    usecase "Umpan Balik TTS (Audio)" as UC_TTS
    usecase "Umpan Balik Vibrasi\n(Haptic)" as UC_Vib
    usecase "Log Obstacle ke Backend" as UC_ObsLog

    ' --- LOKASI ---
    usecase "Kirim Lokasi GPS\nReal-time (WebSocket)" as UC_Location
    usecase "Mode Navigasi\n(OpenStreetMap)" as UC_Navigation
    usecase "\"Where Am I?\"\n(Reverse Geocode)" as UC_WhereAmI

    ' --- VOICE & SHORTCUT ---
    usecase "Perintah Suara\n(Speech-to-Text)" as UC_Voice
    usecase "Shortcut Tombol\nFisik Hardware" as UC_Hardware

    ' --- SOS & DARURAT ---
    usecase "Kirim SOS (Darurat)" as UC_SOS
    usecase "Panggil Guardian\n(VoIP Agora)" as UC_Call
    usecase "Terima Panggilan Masuk" as UC_IncomingCall

    ' --- NOTIFIKASI ---
    usecase "Terima Notifikasi FCM" as UC_FCMReceive
    usecase "Kirim Notifikasi\nTeks / Voice Note" as UC_SendNotif
    usecase "Baca Notifikasi via TTS" as UC_ReadNotif
    usecase "Tandai Notifikasi\nSudah Dibaca" as UC_MarkRead

    ' --- LOG ---
    usecase "Lihat Log Aktivitas" as UC_ViewLog
    usecase "Lihat Log Obstacle" as UC_ViewObsLog

    ' --- PENGATURAN ---
    usecase "Atur Preferensi TTS\n& Haptic" as UC_UserSettings
    usecase "Kelola Perintah\nSuara Kustom" as UC_VoiceConfig
    usecase "Kelola Shortcut\nTombol Fisik" as UC_ShortcutConfig

    ' --- GUARDIAN DASHBOARD ---
    usecase "Monitor Lokasi User\nReal-time (Map)" as UC_MonitorMap
    usecase "Kelola Konfigurasi AI\n(Threshold YOLO)" as UC_AIConfig
    usecase "Kelola Geofence\n(Radius Aman)" as UC_Geofence
    usecase "Kelola Akun\nUser Paired" as UC_ManageUser
    usecase "Konfirmasi/Acknowledge\nSOS" as UC_AckSOS
}

' ==========================================
' AKTOR SISTEM (Kanan)
' ==========================================
rectangle "YOLOv8n\n(On-Device AI)" as AI <<actor>>
rectangle "Spring Boot\nBackend" as Backend <<actor>>
rectangle "Firebase FCM" as FCM <<actor>>
rectangle "Agora RTC" as Agora <<actor>>

' ==========================================
' RELASI USER (ROLE_USER)
' ==========================================
User "*" -- "*" UC_Server
User "*" -- "*" UC_Login
User "*" -- "*" UC_Register
User "*" -- "*" UC_Logout
User "*" -- "*" UC_PairingResponse
User "*" -- "*" UC_Unpair
User "*" -- "*" UC_Walk
User "*" -- "*" UC_Voice
User "*" -- "*" UC_Hardware
User "*" -- "*" UC_SOS
User "*" -- "*" UC_Call
User "*" -- "*" UC_IncomingCall
User "*" -- "*" UC_Navigation
User "*" -- "*" UC_WhereAmI
User "*" -- "*" UC_FCMReceive
User "*" -- "*" UC_ReadNotif
User "*" -- "*" UC_MarkRead
User "*" -- "*" UC_ViewLog
User "*" -- "*" UC_UserSettings
User "*" -- "*" UC_ShortcutConfig

' ==========================================
' RELASI GUARDIAN (ROLE_GUARDIAN)
' ==========================================
Guardian "*" -- "*" UC_Login
Guardian "*" -- "*" UC_Register
Guardian "*" -- "*" UC_Logout
Guardian "*" -- "*" UC_Invite
Guardian "*" -- "*" UC_Unpair
Guardian "*" -- "*" UC_MonitorMap
Guardian "*" -- "*" UC_SendNotif
Guardian "*" -- "*" UC_AIConfig
Guardian "*" -- "*" UC_Geofence
Guardian "*" -- "*" UC_VoiceConfig
Guardian "*" -- "*" UC_ShortcutConfig
Guardian "*" -- "*" UC_ManageUser
Guardian "*" -- "*" UC_IncomingCall
Guardian "*" -- "*" UC_ViewLog
Guardian "*" -- "*" UC_ViewObsLog
Guardian "*" -- "*" UC_Call
Guardian "*" -- "*" UC_AckSOS

' ==========================================
' INCLUDE & EXTEND
' ==========================================
UC_Login ..> UC_JWT : <<include>>
UC_Register ..> UC_JWT : <<include>>
UC_JWT ..> UC_RBAC : <<include>>

UC_Walk ..> UC_Detect : <<include>>
UC_Detect ..> UC_Analyze : <<include>>
UC_Analyze <.. UC_TTS : <<extend>>
UC_Analyze <.. UC_Vib : <<extend>>
UC_Detect ..> UC_ObsLog : <<include>>
UC_Walk ..> UC_Location : <<include>>

UC_Walk <.. UC_Voice : <<extend>>
UC_SOS <.. UC_Voice : <<extend>>
UC_Call <.. UC_Voice : <<extend>>

UC_Walk <.. UC_Hardware : <<extend>>
UC_SOS <.. UC_Hardware : <<extend>>
UC_Call <.. UC_Hardware : <<extend>>

UC_SOS ..> UC_FCMReceive : <<include>>
UC_SendNotif ..> UC_FCMReceive : <<include>>
UC_FCMReceive <.. UC_TTS : <<extend>>
UC_Call <.. UC_IncomingCall : <<extend>>
UC_Geofence <.. UC_FCMReceive : <<extend>>

' ==========================================
' RELASI KE SISTEM EKSTERNAL
' ==========================================
UC_Detect "*" ----- "*" AI
UC_JWT "*" ----- "*" Backend
UC_ObsLog "*" ----- "*" Backend
UC_Location "*" ----- "*" Backend
UC_SOS "*" ----- "*" Backend
UC_SendNotif "*" ----- "*" Backend
UC_ViewLog "*" ----- "*" Backend
UC_ViewObsLog "*" ----- "*" Backend
UC_AIConfig "*" ----- "*" Backend
UC_FCMReceive "*" ----- "*" FCM
UC_SendNotif "*" ----- "*" FCM
UC_Call "*" ----- "*" Agora
UC_IncomingCall "*" ----- "*" Agora

@enduml