package com.lanyuanxiaoyao.leopard.server.entity;

import com.lanyuanxiaoyao.leopard.core.entity.Stock;
import com.lanyuanxiaoyao.leopard.core.entity.StockScore;
import java.time.LocalDate;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author lanyuanxiaoyao
 * @version 20250917
 */
public record StockScoreVo(
  Long id,
  String code,
  String name,
  String fullname,
  Stock.Market market,
  String industry,
  LocalDate listedDate,
  Double score,
  String extra
) {
  public static StockScoreVo of(StockScore score) {
    return new StockScoreVo(
      score.getStock().getId(),
      score.getStock().getCode(),
      score.getStock().getName(),
      score.getStock().getFullname(),
      score.getStock().getMarket(),
      score.getStock().getIndustry(),
      score.getStock().getListedDate(),
      score.getScore(),
      score.getExtra()
        .entrySet()
        .stream()
        .sorted(Map.Entry.comparingByKey())
        .map(entry -> entry.getKey() + ": " + entry.getValue())
        .collect(Collectors.joining("<br>"))
    );
  }
}
