package jp.kobe_u.cs27.newse.medicalcheck.dto;

import java.text.SimpleDateFormat;

import jp.kobe_u.cs27.newse.medicalcheck.entity.Person;
import lombok.Data;

/**
 * 受診者DTO．受診者エンティティのデータに加えて，BMI，肥満度を含む．
 */
@Data
public class PersonDto {
    private Long number;
    private String name;
    private String birthday;
    private double height;
    private double weight;

    private double bmi;
    private String obesity;

    /**
     * 受診者エンティティからDTOを作成する
     * @param person
     * @return
     */
    public static PersonDto build(Person person) {
        PersonDto dto = new PersonDto();
        dto.number = person.getNumber();
        dto.name = person.getName();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        dto.birthday = sdf.format(person.getBirthday());
        dto.height = person.getHeight();
        dto.weight = person.getWeight();
        dto.bmi = dto.weight / ((dto.height * 0.01) * (dto.height * 0.01));
        double bmi = dto.bmi;
        String obesity = "";
        if (bmi < 18.5) {
            obesity = "低体重";
        } else if (18.5 <= bmi && bmi < 25) {
            obesity = "普通体重";
        } else if (25 <= bmi && bmi < 30) {
            obesity = "肥満 (1度)";
        } else if (30 <= bmi && bmi < 35) {
            obesity = "肥満 (2度)";
        } else if (35 <= bmi && bmi < 40) {
            obesity = "肥満 (3度)";
        } else if (40 <= bmi) {
            obesity = "肥満 (4度)";
        } else {
            obesity = "不明";
        }
        dto.obesity = obesity;

        return dto;
    }

}