package com.eactive.eai.rms.onl.dashboard.modern.dto;

/**
 * 배치 처리 현황 DTO
 */
public class BatchProcessDTO {
    private String serviceType;  // BAP 또는 BAT
    private String procBatch;    // 원본 CSV 데이터
    private int sendSuccess;     // 송신 성공
    private int receiveSuccess;  // 수신 성공
    private int sendError;       // 송신 에러
    private int receiveError;    // 수신 에러
    private int sendWaiting;     // 송신 대기
    private int receiveWaiting;  // 수신 대기

    public BatchProcessDTO() {
        // 기본 생성자
    }

    public String getServiceType() {
        return serviceType;
    }

    public void setServiceType(String serviceType) {
        this.serviceType = serviceType;
    }

    public String getProcBatch() {
        return procBatch;
    }

    public void setProcBatch(String procBatch) {
        this.procBatch = procBatch;

        // CSV 데이터 파싱
        if (procBatch != null && !procBatch.isEmpty()) {
            String[] fields = procBatch.split(",");
            if (fields.length >= 6) {
                try {
                    this.sendSuccess = Integer.parseInt(fields[0].trim());
                    this.receiveSuccess = Integer.parseInt(fields[1].trim());
                    this.sendError = Integer.parseInt(fields[2].trim());
                    this.receiveError = Integer.parseInt(fields[3].trim());
                    this.sendWaiting = Integer.parseInt(fields[4].trim());
                    this.receiveWaiting = Integer.parseInt(fields[5].trim());
                } catch (NumberFormatException e) {
                    // 파싱 실패 시 기본값 유지
                }
            }
        }
    }

    public int getSendSuccess() {
        return sendSuccess;
    }

    public void setSendSuccess(int sendSuccess) {
        this.sendSuccess = sendSuccess;
    }

    public int getReceiveSuccess() {
        return receiveSuccess;
    }

    public void setReceiveSuccess(int receiveSuccess) {
        this.receiveSuccess = receiveSuccess;
    }

    public int getSendError() {
        return sendError;
    }

    public void setSendError(int sendError) {
        this.sendError = sendError;
    }

    public int getReceiveError() {
        return receiveError;
    }

    public void setReceiveError(int receiveError) {
        this.receiveError = receiveError;
    }

    public int getSendWaiting() {
        return sendWaiting;
    }

    public void setSendWaiting(int sendWaiting) {
        this.sendWaiting = sendWaiting;
    }

    public int getReceiveWaiting() {
        return receiveWaiting;
    }

    public void setReceiveWaiting(int receiveWaiting) {
        this.receiveWaiting = receiveWaiting;
    }

    /**
     * 총 송신 건수 반환
     */
    public int getTotalSend() {
        return sendSuccess + sendError + sendWaiting;
    }

    /**
     * 총 수신 건수 반환
     */
    public int getTotalReceive() {
        return receiveSuccess + receiveError + receiveWaiting;
    }

    /**
     * 총 처리 건수 반환
     */
    public int getTotal() {
        return getTotalSend() + getTotalReceive();
    }

    /**
     * 송신 오류율 계산 (%)
     */
    public double getSendErrorRate() {
        if (getTotalSend() == 0) {
            return 0.0;
        }
        return (double) sendError / getTotalSend() * 100;
    }

    /**
     * 수신 오류율 계산 (%)
     */
    public double getReceiveErrorRate() {
        if (getTotalReceive() == 0) {
            return 0.0;
        }
        return (double) receiveError / getTotalReceive() * 100;
    }
}