package com.njzscloud.common.sn.support;

import java.util.List;
import java.util.stream.Collectors;

public class Sn {
    private final List<ISnSection> sections;

    public Sn(List<SectionConfig> configs) {
        this.sections = configs.stream().map(SectionConfig::section).collect(Collectors.toList());
    }

    public Sn() {
        this.sections = null;
    }

    public String next() {
        if (sections == null || sections.isEmpty()) {
            return null;
        }
        return sections.stream()
                .map(ISnSection::next)
                .reduce((a, b) -> a + b)
                .orElseThrow(() -> new RuntimeException("No section found"));
    }
}
