package com.ruoyi.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 门户视频生成参数（模型、比例、时长、分辨率等从配置读取，不在代码中写死业务默认值）。
 */
@Component
@ConfigurationProperties(prefix = "portal.video")
public class PortalVideoProperties {

    private Defaults defaults = new Defaults();

    private List<ModelOption> models = new ArrayList<>();

    private List<String> ratios = new ArrayList<>();

    private List<Integer> durations = new ArrayList<>();

    private List<String> resolutions = new ArrayList<>();

    public Defaults getDefaults() {
        return defaults;
    }

    public void setDefaults(Defaults defaults) {
        if (defaults != null) {
            this.defaults = defaults;
        }
    }

    public List<ModelOption> getModels() {
        return models;
    }

    public void setModels(List<ModelOption> models) {
        this.models = models != null ? models : new ArrayList<>();
    }

    public List<String> getRatios() {
        return ratios;
    }

    public void setRatios(List<String> ratios) {
        this.ratios = ratios != null ? ratios : new ArrayList<>();
    }

    public List<Integer> getDurations() {
        return durations;
    }

    public void setDurations(List<Integer> durations) {
        this.durations = durations != null ? durations : new ArrayList<>();
    }

    public List<String> getResolutions() {
        return resolutions;
    }

    public void setResolutions(List<String> resolutions) {
        this.resolutions = resolutions != null ? resolutions : new ArrayList<>();
    }

    /**
     * defaults.model 为空时，取 models 第一项的 value。
     */
    public String resolveDefaultModelId() {
        if (defaults.getModel() != null && !defaults.getModel().isEmpty()) {
            return defaults.getModel();
        }
        if (!models.isEmpty() && models.get(0).getValue() != null) {
            return models.get(0).getValue();
        }
        return null;
    }

    public static class Defaults {
        private String model;
        private Integer duration;
        private String resolution;
        private String ratio;

        public String getModel() {
            return model;
        }

        public void setModel(String model) {
            this.model = model;
        }

        public Integer getDuration() {
            return duration;
        }

        public void setDuration(Integer duration) {
            this.duration = duration;
        }

        public String getResolution() {
            return resolution;
        }

        public void setResolution(String resolution) {
            this.resolution = resolution;
        }

        public String getRatio() {
            return ratio;
        }

        public void setRatio(String ratio) {
            this.ratio = ratio;
        }
    }

    public static class ModelOption {
        private String label;
        private String value;

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }
}
