package quant.rich.emoney.pojo.dto;

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

import com.fasterxml.jackson.annotation.JsonView;

import lombok.Data;
import quant.rich.emoney.util.HtmlSanitizer;

@Data
public class ParamsIndexDetail implements IndexDetail {

    @JsonView(IndexDetail.class)
    private String id;
    @JsonView(IndexDetail.class)
    private String name;
    @JsonView(IndexDetail.class)
    private String code;
    @JsonView(IndexDetail.class)
    private List<String> descriptions = new ArrayList<>();
    @JsonView(IndexDetail.class)
    private String original;
    
    @Override
    public String getIndexName() {
        return name;
    }
    
    @Override
    public String getIndexCode() {
        return code;
    }
    
    @Override
    public List<Detail> getDetails() {
        List<Detail> list = new ArrayList<>();
        descriptions.forEach(des -> {
            list.add(new Detail().setContent(des).setType(DetailType.TEXT));
        });
        return list;
    }
    
    @Override
    public void sanitize() {
        List<String> descriptions = new ArrayList<>();
        for (String description : getDescriptions()) {
            descriptions.add(HtmlSanitizer.sanitize(description));
        }
        setDescriptions(descriptions);
    }

}
