spring:
  application:
    name: analytics-service

  # Database
  datasource:
    url: jdbc:postgresql://${DB_HOST:4.230.49.9}:${DB_PORT:5432}/${DB_NAME:analytics_db}
    username: ${DB_USERNAME:analytics_user}
    password: ${DB_PASSWORD:analytics_pass}
    driver-class-name: org.postgresql.Driver
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5
      connection-timeout: 30000
      idle-timeout: 600000
      max-lifetime: 1800000
      leak-detection-threshold: 60000

  # JPA
  jpa:
    show-sql: ${SHOW_SQL:true}
    properties:
      hibernate:
        format_sql: true
        use_sql_comments: true
        dialect: org.hibernate.dialect.PostgreSQLDialect
    hibernate:
      ddl-auto: ${DDL_AUTO:update}

  # Redis
  data:
    redis:
      host: ${REDIS_HOST:20.214.210.71}
      port: ${REDIS_PORT:6379}
      password: ${REDIS_PASSWORD:Hi5Jessica!}
      timeout: 2000ms
      lettuce:
        pool:
          max-active: 8
          max-idle: 8
          min-idle: 0
          max-wait: -1ms
      database: ${REDIS_DATABASE:5}

  # Kafka (원격 서버 사용)
  kafka:
    enabled: ${KAFKA_ENABLED:true}
    bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:20.249.182.13:9095,4.217.131.59:9095}
    consumer:
      group-id: ${KAFKA_CONSUMER_GROUP_ID:analytics-service-consumers-v3}
      auto-offset-reset: earliest
      enable-auto-commit: true
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      properties:
        auto.offset.reset: earliest
    producer:
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer
      acks: all
      retries: 3
    properties:
      connections.max.idle.ms: 540000
      request.timeout.ms: 30000
      session.timeout.ms: 30000
      heartbeat.interval.ms: 3000
      max.poll.interval.ms: 300000

  # Sample Data (MVP Only)
  # ⚠️ 실제 운영: false로 설정 (다른 서비스들이 이벤트 발행)
  # ⚠️ MVP 환경: true로 설정 (SampleDataLoader가 이벤트 발행)
  sample-data:
    enabled: ${SAMPLE_DATA_ENABLED:true}

# Server
server:
  port: ${SERVER_PORT:8086}
  servlet:
    context-path: /api/v1/analytics
    encoding:
      charset: UTF-8
      enabled: true
      force: true

# JWT
jwt:
  secret: ${JWT_SECRET:}
  access-token-validity: ${JWT_ACCESS_TOKEN_VALIDITY:1800}
  refresh-token-validity: ${JWT_REFRESH_TOKEN_VALIDITY:86400}

# CORS Configuration
cors:
  allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io}
  allowed-methods: ${CORS_ALLOWED_METHODS:GET,POST,PUT,DELETE,OPTIONS,PATCH}
  allowed-headers: ${CORS_ALLOWED_HEADERS:*}
  allow-credentials: ${CORS_ALLOW_CREDENTIALS:true}
  max-age: ${CORS_MAX_AGE:3600}

# Actuator
management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics,prometheus
      base-path: /actuator
  endpoint:
    health:
      show-details: always
      show-components: always
  health:
    livenessState:
      enabled: true
    readinessState:
      enabled: true

# OpenAPI Documentation
springdoc:
  api-docs:
    path: /v3/api-docs
  swagger-ui:
    path: /swagger-ui.html
    tags-sorter: alpha
    operations-sorter: alpha
  show-actuator: false

# Logging
logging:
  level:
    com.kt.event.analytics: ${LOG_LEVEL_APP:DEBUG}
    org.springframework.web: ${LOG_LEVEL_WEB:INFO}
    org.hibernate.SQL: ${LOG_LEVEL_SQL:DEBUG}
    org.hibernate.type: ${LOG_LEVEL_SQL_TYPE:TRACE}
  pattern:
    console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"
    file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
  file:
    name: ${LOG_FILE:logs/analytics-service.log}
  logback:
    rollingpolicy:
      max-file-size: 10MB
      max-history: 7
      total-size-cap: 100MB

# Resilience4j Circuit Breaker
resilience4j:
  circuitbreaker:
    instances:
      wooriTV:
        failure-rate-threshold: 50
        wait-duration-in-open-state: 30s
        sliding-window-size: 10
        permitted-number-of-calls-in-half-open-state: 3
      genieTV:
        failure-rate-threshold: 50
        wait-duration-in-open-state: 30s
        sliding-window-size: 10
      ringoBiz:
        failure-rate-threshold: 50
        wait-duration-in-open-state: 30s
        sliding-window-size: 10
      sns:
        failure-rate-threshold: 50
        wait-duration-in-open-state: 30s
        sliding-window-size: 10

# Batch Scheduler
batch:
  analytics:
    refresh-interval: ${BATCH_REFRESH_INTERVAL:300000}  # 5분 (밀리초)
    initial-delay: ${BATCH_INITIAL_DELAY:30000}         # 30초 (밀리초)
    enabled: ${BATCH_ENABLED:true}                      # 배치 활성화 여부
