package jnpf.model.attendance.model;

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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class LeaveStatisticsTotal {
    /**
     * 总天数
     */
    private BigDecimal daysTotal = BigDecimal.ZERO;
    /**
     * 总小时数
     */
    private BigDecimal hoursTotal = BigDecimal.ZERO;
    /**
     * 总计薪小时数
     */
    private BigDecimal payrollHoursTotal = BigDecimal.ZERO;
    /**
     * 请假详情
     */
    private final List<LeaveTypeStaDetailsModel> detailList = new ArrayList<>();

    public void add(ProcessResult result) {
        this.daysTotal = daysTotal.add(normalizeDays(result.getDays()));
        this.hoursTotal = hoursTotal.add(result.getHours());
        this.payrollHoursTotal = payrollHoursTotal.add(result.getPayrollHours());
    }

    public void addDetail(LeaveTypeStaDetailsModel detail) {
        detailList.add(detail);
    }

    private BigDecimal normalizeDays(BigDecimal days) {
        return days.compareTo(BigDecimal.ONE) > 0 ? BigDecimal.ONE : days;
    }
}
