spring:
  application:
    name: distribution-service

  # Database Configuration
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://${DB_HOST:4.217.133.59}:${DB_PORT:5432}/${DB_NAME:distributiondb}
    username: ${DB_USERNAME:eventuser}
    password: ${DB_PASSWORD:Hi5Jessica!}
    hikari:
      maximum-pool-size: 10
      minimum-idle: 5
      connection-timeout: 30000
      idle-timeout: 600000
      max-lifetime: 1800000

  jpa:
    hibernate:
      ddl-auto: ${JPA_DDL_AUTO:update}
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true
        show_sql: ${JPA_SHOW_SQL:false}

  # Redis Configuration
  data:
    redis:
      host: ${REDIS_HOST:20.214.210.71}
      port: ${REDIS_PORT:6379}
      password: ${REDIS_PASSWORD:Hi5Jessica!}
      timeout: 3000ms
      lettuce:
        pool:
          max-active: 8
          max-idle: 8
          min-idle: 2

  # Disable security and kafka auto-configuration
  autoconfigure:
    exclude:
      - org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
      - org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
      - org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration

  kafka:
    enabled: ${KAFKA_ENABLED:true}
    bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:20.249.182.13:9095,4.217.131.59:9095}
    producer:
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
      properties:
        spring.json.type.mapping: distributionCompleted:com.kt.distribution.event.DistributionCompletedEvent
    consumer:
      group-id: ${KAFKA_CONSUMER_GROUP:distribution-service}
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
      properties:
        spring.json.trusted.packages: '*'

# Kafka Topics
kafka:
  topics:
    distribution-completed: distribution-completed

# Server Configuration
server:
  port: ${SERVER_PORT:8085}
  servlet:
    context-path: /api/v1/distribution

# Resilience4j Configuration
resilience4j:
  circuitbreaker:
    instances:
      channelApi:
        failure-rate-threshold: 50
        slow-call-rate-threshold: 50
        slow-call-duration-threshold: 5000ms
        wait-duration-in-open-state: 30s
        permitted-number-of-calls-in-half-open-state: 3
        sliding-window-type: COUNT_BASED
        sliding-window-size: 10
        minimum-number-of-calls: 5

  retry:
    instances:
      channelApi:
        max-attempts: 3
        wait-duration: 1s
        exponential-backoff-multiplier: 2
        retry-exceptions:
          - java.net.SocketTimeoutException
          - java.net.ConnectException
          - org.springframework.web.client.ResourceAccessException

  bulkhead:
    instances:
      channelApi:
        max-concurrent-calls: 10
        max-wait-duration: 0ms

# External Channel APIs (Mock URLs)
channel:
  apis:
    uridongnetv:
      url: ${URIDONGNETV_API_URL:http://localhost:9001/api/uridongnetv}
      timeout: 10000
    ringobiz:
      url: ${RINGOBIZ_API_URL:http://localhost:9002/api/ringobiz}
      timeout: 10000
    ginitv:
      url: ${GINITV_API_URL:http://localhost:9003/api/ginitv}
      timeout: 10000
    instagram:
      url: ${INSTAGRAM_API_URL:http://localhost:9004/api/instagram}
      timeout: 10000
    naver:
      url: ${NAVER_API_URL:http://localhost:9005/api/naver}
      timeout: 10000
    kakao:
      url: ${KAKAO_API_URL:http://localhost:9006/api/kakao}
      timeout: 10000

# Naver Blog Configuration (Playwright 기반)
naver:
  blog:
    enabled: ${NAVER_BLOG_ENABLED:false}
    username: ${NAVER_BLOG_USERNAME:}
    password: ${NAVER_BLOG_PASSWORD:}
    blog-id: ${NAVER_BLOG_ID:}
    headless: ${NAVER_BLOG_HEADLESS:false}
    session-path: ${NAVER_BLOG_SESSION_PATH:playwright-sessions}

# Springdoc OpenAPI (Swagger)
springdoc:
  api-docs:
    path: /v3/api-docs
    enabled: true
  swagger-ui:
    path: /swagger-ui.html
    enabled: true
    operations-sorter: alpha
    tags-sorter: alpha
    display-request-duration: true
  show-actuator: true

# 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}

# Logging
logging:
  file:
    name: ${LOG_FILE:logs/distribution-service.log}
  logback:
    rollingpolicy:
      max-file-size: 10MB
      max-history: 7
      total-size-cap: 100MB
  level:
    com.kt.distribution: DEBUG
    org.springframework.kafka: INFO
    io.github.resilience4j: DEBUG
    org.springframework.web: DEBUG
