package cn.lihongjie.coal.coalBlend.dto;

import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import cn.lihongjie.coal.coalBlend.entity.CoalPercentVo;

import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CoalBlendResultInfoDto extends OrgCommonDto {

    @NotEmpty(message = "煤名称不能为空")
    private String name;

    private List<CoalPercentVo> percentInfos;
    private Double percentSum;
    @Comment("参数 1 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param1;

    @Comment("参数 2 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param2;

    @Comment("参数 3 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param3;

    @Comment("参数 4 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param4;

    @Comment("参数 5 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param5;

    @Comment("参数 6 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param6;

    @Comment("参数 7 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param7;

    @Comment("参数 8 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param8;

    @Comment("参数 9 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param9;

    @Comment("参数 10 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param10;

    @Comment("参数 11 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param11;

    @Comment("参数 12 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param12;

    @Comment("参数 13 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param13;

    @Comment("参数 14 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param14;

    @Comment("参数 15 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param15;

    @Comment("参数 16 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param16;

    @Comment("参数 17 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param17;

    @Comment("参数 18 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param18;

    @Comment("参数 19 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param19;

    @Comment("参数 20 ")
    @DecimalMin(
            groups = CoalBlendEntity.BlendGroup.class,
            value = "0.1",
            inclusive = true,
            message = "参数不能小于0.1")
    private Double param20;

    @SneakyThrows
    public Double getParam(String param) {
        return (Double) FieldUtils.getField(this.getClass(), param, true).get(this);
    }

    public long getHashKey() {

        return Arrays.hashCode(
                this.getPercentInfos().stream()
                        .sorted(Comparator.comparing(x -> x.getPercent()))
                        .toArray(CoalPercentVo[]::new));
    }
}
