package com.stevesoltys.telegramirc.configuration.telegram;

import com.stevesoltys.telegramirc.configuration.ConfigurationException;
import com.stevesoltys.telegramirc.protocol.telegram.message.decoder.image.impl.DefaultImageDecoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Steve Soltys
 */
@Component
public class TelegramDecoderConfiguration {

    private static final String CONFIGURATION_KEY = "decoders";

    private static final String IMAGE_DECODER_KEY = "image_decoder";

    private static final String DEFAULT_IMAGE_DECODER = DefaultImageDecoder.IDENTIFIER;

    private final ImgurDecoderConfiguration imgurDecoderConfiguration;

    private String imageDecoder;

    @Autowired
    public TelegramDecoderConfiguration(ImgurDecoderConfiguration imgurDecoderConfiguration) {
        this.imgurDecoderConfiguration = imgurDecoderConfiguration;

        imageDecoder = DEFAULT_IMAGE_DECODER;
    }

    @SuppressWarnings("unchecked")
    public void initialize(Map<String, Object> configuration) {
        Map<String, Object> decoderConfiguration = (Map<String, Object>) configuration.get(CONFIGURATION_KEY);

        if (decoderConfiguration == null) {
            throw new ConfigurationException("Could not find 'decoders' entry in 'telegram'.");
        }

        imageDecoder = (String) decoderConfiguration.getOrDefault(IMAGE_DECODER_KEY, DEFAULT_IMAGE_DECODER);
        imgurDecoderConfiguration.initialize(decoderConfiguration);
    }

    public String getImageDecoder() {
        return imageDecoder;
    }
}

@@ -619,29 +619,194 @@
  String 
-DEFAULT_IMAGE
+STICKER_DECODER_KEY = %22sticker_decoder%22;%0A%0A    private static final String DEFAULT_IMAGE_DECODER = DefaultImageDecoder.IDENTIFIER;%0A%0A    private static final String DEFAULT_STICKER
 _DECODER
@@ -909,24 +909,24 @@
 iguration;%0A%0A
-
     private 
@@ -947,16 +947,52 @@
 coder;%0A%0A
+    private String stickerDecoder;%0A%0A
     @Aut
@@ -1686,16 +1686,132 @@
 CODER);%0A
+        stickerDecoder = (String) decoderConfiguration.getOrDefault(STICKER_DECODER_KEY, DEFAULT_STICKER_DECODER);%0A%0A
         
@@ -1949,11 +1949,89 @@
 r;%0A    %7D
+%0A%0A    public String getStickerDecoder() %7B%0A        return stickerDecoder;%0A    %7D
 %0A%7D%0A

Add sticker decoder configuration