package com.eactive.eai.data.entity.custom.statistics;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import org.hibernate.annotations.Comment;

import lombok.Getter;
import lombok.Setter;

/**
 * API Gateway 분단위 처리 통계
 */
@Getter
@Setter
@Entity
@Table(name = "API_STATS_MINUTE")
@org.hibernate.annotations.Table(appliesTo = "API_STATS_MINUTE", comment = "API Gateway 분단위 처리 통계")
@IdClass(ApiStatsMinuteId.class)
public class ApiStatsMinute implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "STAT_TIME", nullable = false)
	@Comment("통계시간(분단위, 초는 00초로 절사)")
	private LocalDateTime statTime;

	@Id
	@Column(name = "API_NAME", nullable = false, length = 100)
	@Comment("API 명칭")
	private String apiName;

	@Id
	@Column(name = "GW_INSTANCE_ID", nullable = false, length = 50)
	@Comment("API Gateway 인스턴스 ID")
	private String gwInstanceId;

	@Id
	@Column(name = "BIZ_DIV_CODE", nullable = false, length = 50, columnDefinition = "VARCHAR2(50) DEFAULT 'NONE'")
	@Comment("업무구분코드 (없으면 NONE)")
	private String bizDivCode = "NONE";

	@Id
	@Column(name = "CLIENT_ID", nullable = false, length = 100, columnDefinition = "VARCHAR2(100) DEFAULT 'NONE'")
	@Comment("클라이언트 ID (없으면 NONE)")
	private String clientId = "NONE";

	@Id
	@Column(name = "INBOUND_ADAPTER", nullable = false, length = 100, columnDefinition = "VARCHAR2(100) DEFAULT 'NONE'")
	@Comment("Inbound Adapter (없으면 NONE)")
	private String inboundAdapter = "NONE";

	@Id
	@Column(name = "OUTBOUND_ADAPTER", nullable = false, length = 100, columnDefinition = "VARCHAR2(100) DEFAULT 'NONE'")
	@Comment("Outbound Adapter (없으면 NONE)")
	private String outboundAdapter = "NONE";

	// 건수 메트릭
	@Column(name = "TOTAL_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("총 처리 건수")
	private Long totalCnt = 0L;

	@Column(name = "SUCCESS_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("성공 건수")
	private Long successCnt = 0L;

	@Column(name = "TIMEOUT_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("Timeout 오류 건수")
	private Long timeoutCnt = 0L;

	@Column(name = "SYSTEM_ERR_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("시스템 오류 건수")
	private Long systemErrCnt = 0L;

	@Column(name = "BIZ_ERR_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("업무 오류 건수")
	private Long bizErrCnt = 0L;

	@Column(name = "SEQ900_TIMEOUT_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("로그시퀀스900 Timeout 오류 건수")
	private Long seq900TimeoutCnt = 0L;

	@Column(name = "SEQ900_SYSTEM_ERR_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("로그시퀀스900 시스템 오류 건수")
	private Long seq900SystemErrCnt = 0L;

	@Column(name = "SEQ900_BIZ_ERR_CNT", nullable = false, precision = 12, columnDefinition = "NUMBER(12) DEFAULT 0")
	@Comment("로그시퀀스900 업무 오류 건수")
	private Long seq900BizErrCnt = 0L;

	// 응답시간 메트릭 (ms, 소수점 3자리)
	@Column(name = "AVG_RESP_TIME", precision = 10, scale = 3, columnDefinition = "NUMBER(10,3) DEFAULT 0")
	@Comment("평균 응답시간(ms)")
	private BigDecimal avgRespTime = BigDecimal.ZERO;

	@Column(name = "MIN_RESP_TIME", precision = 10, scale = 3, columnDefinition = "NUMBER(10,3) DEFAULT 0")
	@Comment("최소 응답시간(ms)")
	private BigDecimal minRespTime = BigDecimal.ZERO;

	@Column(name = "MAX_RESP_TIME", precision = 10, scale = 3, columnDefinition = "NUMBER(10,3) DEFAULT 0")
	@Comment("최대 응답시간(ms)")
	private BigDecimal maxRespTime = BigDecimal.ZERO;

	@Column(name = "P50_RESP_TIME", precision = 10, scale = 3, columnDefinition = "NUMBER(10,3) DEFAULT 0")
	@Comment("50 백분위 응답시간(ms)")
	private BigDecimal p50RespTime = BigDecimal.ZERO;

	@Column(name = "P95_RESP_TIME", precision = 10, scale = 3, columnDefinition = "NUMBER(10,3) DEFAULT 0")
	@Comment("95 백분위 응답시간(ms)")
	private BigDecimal p95RespTime = BigDecimal.ZERO;
}
