package com.arms.api.report.rolling3m.model.vo;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

/**
 * Node = 암스 요구사항 + alm 이슈의 상위 개념
 *
 * 팀별 노드 평균 통계 처리
 */
@Getter
@Builder(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class IssueAverageByTeamVO {

    private final IssueByTeamVO overall;
    private final IssueByTeamVO requirement;
    private final IssueByTeamVO issue;

    private final double teamAverage;
    private final double reqTeamAverage;
    private final double issueTeamAverage;

    public static IssueAverageByTeamVO of(IssueByTeamVO overall, IssueByTeamVO requirement, IssueByTeamVO issue) {
        return IssueAverageByTeamVO.builder()
                .overall(overall)
                .requirement(requirement)
                .issue(issue)
                .teamAverage(computeAverage(overall))
                .reqTeamAverage(computeAverage(requirement))
                .issueTeamAverage(computeAverage(issue))
                .build();
    }

    private static double computeAverage(IssueByTeamVO stats) {
        if (stats.getAssigneeCount() == 0) return 0.0;
        return Math.round((double) stats.getTotalHits() / stats.getAssigneeCount() * 10.0) / 10.0;
    }
}
