package com.mosquito.project.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
@ConfigurationProperties(prefix = "app.poster")
public class PosterConfig {

    private String defaultTemplate = "default";
    private Map<String, PosterTemplate> templates = new HashMap<>();
    private String cdnBaseUrl = "https://cdn.example.com";

    public static class PosterTemplate {
        private int width = 600;
        private int height = 800;
        private String background;
        private String backgroundColor = "#ffffff";
        private Map<String, PosterElement> elements = new HashMap<>();

        public int getWidth() { return width; }
        public void setWidth(int width) { this.width = width; }
        public int getHeight() { return height; }
        public void setHeight(int height) { this.height = height; }
        public String getBackground() { return background; }
        public void setBackground(String background) { this.background = background; }
        public String getBackgroundColor() { return backgroundColor; }
        public void setBackgroundColor(String backgroundColor) { this.backgroundColor = backgroundColor; }
        public Map<String, PosterElement> getElements() { return elements; }
        public void setElements(Map<String, PosterElement> elements) { this.elements = elements; }
    }

    public static class PosterElement {
        private String type;
        private int x;
        private int y;
        private int width;
        private int height;
        private String content;
        private String color = "#000000";
        private String fontSize = "16px";
        private String fontFamily = "SansSerif";
        private String textAlign = "center";
        private String background;
        private String borderRadius;
        private int opacity = 100;

        public String getType() { return type; }
        public void setType(String type) { this.type = type; }
        public int getX() { return x; }
        public void setX(int x) { this.x = x; }
        public int getY() { return y; }
        public void setY(int y) { this.y = y; }
        public int getWidth() { return width; }
        public void setWidth(int width) { this.width = width; }
        public int getHeight() { return height; }
        public void setHeight(int height) { this.height = height; }
        public String getContent() { return content; }
        public void setContent(String content) { this.content = content; }
        public String getColor() { return color; }
        public void setColor(String color) { this.color = color; }
        public String getFontSize() { return fontSize; }
        public void setFontSize(String fontSize) { this.fontSize = fontSize; }
        public String getFontFamily() { return fontFamily; }
        public void setFontFamily(String fontFamily) { this.fontFamily = fontFamily; }
        public String getTextAlign() { return textAlign; }
        public void setTextAlign(String textAlign) { this.textAlign = textAlign; }
        public String getBackground() { return background; }
        public void setBackground(String background) { this.background = background; }
        public String getBorderRadius() { return borderRadius; }
        public void setBorderRadius(String borderRadius) { this.borderRadius = borderRadius; }
        public int getOpacity() { return opacity; }
        public void setOpacity(int opacity) { this.opacity = opacity; }
    }

    public String getDefaultTemplate() { return defaultTemplate; }
    public void setDefaultTemplate(String defaultTemplate) { this.defaultTemplate = defaultTemplate; }
    public Map<String, PosterTemplate> getTemplates() { return templates; }
    public void setTemplates(Map<String, PosterTemplate> templates) { this.templates = templates; }
    public String getCdnBaseUrl() { return cdnBaseUrl; }
    public void setCdnBaseUrl(String cdnBaseUrl) { this.cdnBaseUrl = cdnBaseUrl; }

    public PosterTemplate getTemplate(String name) {
        return templates.getOrDefault(name, templates.get(defaultTemplate));
    }
}
