@startuml
!theme mono

title User Service 클래스 다이어그램 (요약)

' ====================
' Layered Architecture
' ====================

package "Presentation Layer" {
    class UserController {
        + register()
        + login()
        + logout()
        + getProfile()
        + updateProfile()
        + changePassword()
    }
}

package "Business Layer" {
    interface UserService {
        + register()
        + getProfile()
        + updateProfile()
        + changePassword()
        + updateLastLoginAt()
    }

    interface AuthenticationService {
        + login()
        + logout()
    }

    class UserServiceImpl implements UserService
    class AuthenticationServiceImpl implements AuthenticationService
}

package "Data Access Layer" {
    interface UserRepository
    interface StoreRepository
}

package "Domain Layer" {
    class User {
        - id: UUID
        - name: String
        - phoneNumber: String
        - email: String
        - passwordHash: String
        - role: UserRole
        - status: UserStatus
        - lastLoginAt: LocalDateTime
    }

    class Store {
        - id: UUID
        - name: String
        - industry: String
        - address: String
        - businessHours: String
    }

    enum UserRole {
        OWNER
        ADMIN
    }

    enum UserStatus {
        ACTIVE
        INACTIVE
        LOCKED
        WITHDRAWN
    }
}

package "DTO Layer" {
    class "Request DTOs" as RequestDTO {
        RegisterRequest
        LoginRequest
        UpdateProfileRequest
        ChangePasswordRequest
    }

    class "Response DTOs" as ResponseDTO {
        RegisterResponse
        LoginResponse
        LogoutResponse
        ProfileResponse
    }
}

package "Exception Layer" {
    enum UserErrorCode {
        USER_DUPLICATE_EMAIL
        USER_DUPLICATE_PHONE
        USER_NOT_FOUND
        AUTH_FAILED
        AUTH_INVALID_TOKEN
        PWD_INVALID_CURRENT
        PWD_SAME_AS_CURRENT
    }
}

package "Configuration Layer" {
    class SecurityConfig
    class RedisConfig
    class AsyncConfig
    class SwaggerConfig
}

' ====================
' Layer 간 의존성
' ====================

' Vertical dependencies (Top → Bottom)
UserController --> UserService
UserController --> AuthenticationService

UserServiceImpl --> UserRepository
UserServiceImpl --> StoreRepository
AuthenticationServiceImpl --> UserRepository
AuthenticationServiceImpl --> StoreRepository

UserRepository --> User
StoreRepository --> Store

' DTO usage
UserController ..> RequestDTO : uses
UserController ..> ResponseDTO : uses
UserServiceImpl ..> RequestDTO : uses
UserServiceImpl ..> ResponseDTO : uses
AuthenticationServiceImpl ..> RequestDTO : uses
AuthenticationServiceImpl ..> ResponseDTO : uses

' Domain relationships
User "1" -- "0..1" Store : has >
User +-- UserRole
User +-- UserStatus

' Exception
UserServiceImpl ..> UserErrorCode : throws
AuthenticationServiceImpl ..> UserErrorCode : throws

' Configuration
SecurityConfig ..> UserService : configures
RedisConfig ..> UserServiceImpl : provides Redis

' ====================
' Architecture Notes
' ====================

note top of UserController
  <b>Presentation Layer</b>
  REST API 엔드포인트
end note

note top of UserService
  <b>Business Layer</b>
  비즈니스 로직 처리
  트랜잭션 관리
end note

note top of UserRepository
  <b>Data Access Layer</b>
  JPA 기반 CRUD
end note

note top of User
  <b>Domain Layer</b>
  비즈니스 엔티티
  도메인 로직
end note

note bottom of "Presentation Layer"
  <b>Layered Architecture Pattern</b>

  각 계층은 바로 아래 계층만 의존
  상위 계층은 하위 계층을 알지만
  하위 계층은 상위 계층을 모름
end note

note right of UserServiceImpl
  <b>핵심 비즈니스 플로우</b>

  1. 회원가입
     - 중복 검증
     - 비밀번호 해싱
     - User/Store 생성
     - JWT 발급
     - Redis 세션 저장

  2. 로그인
     - 인증 정보 검증
     - JWT 발급
     - 최종 로그인 시각 업데이트

  3. 프로필 관리
     - 조회/수정
     - 비밀번호 변경

  4. 로그아웃
     - Redis 세션 삭제
     - JWT Blacklist 추가
end note

note right of User
  <b>도메인 특성</b>

  - User와 Store는 1:1 관계
  - UserRole: OWNER(소상공인), ADMIN
  - UserStatus: ACTIVE, INACTIVE,
                LOCKED, WITHDRAWN
  - JWT 기반 인증
  - Redis 세션 관리
end note

@enduml
