package com.kamco.cd.training.postgres.entity;

import com.kamco.cd.training.log.dto.ErrorLogDto;
import com.kamco.cd.training.log.dto.EventType;
import com.kamco.cd.training.postgres.CommonCreateEntity;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "tb_error_log")
public class ErrorLogEntity extends CommonCreateEntity {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "error_log_uid", nullable = false)
  private Long id;

  @Column(name = "request_id")
  private String requestId;

  @Column(name = "error_type")
  @Enumerated(EnumType.STRING)
  private EventType errorType;

  @Enumerated(EnumType.STRING)
  private ErrorLogDto.LogErrorLevel errorLevel;

  private String errorCode;
  private String errorMessage;

  @Size(max = 255)
  @Column(name = "stack_trace")
  private String stackTrace;

  private Long handlerUid;
  private ZonedDateTime handledDttm;

  public ErrorLogEntity(
      String requestId,
      EventType errorType,
      ErrorLogDto.LogErrorLevel errorLevel,
      String errorCode,
      String errorMessage,
      String stackTrace,
      Long handlerUid,
      ZonedDateTime handledDttm) {
    this.requestId = requestId;
    this.errorType = errorType;
    this.errorLevel = errorLevel;
    this.errorCode = errorCode;
    this.errorMessage = errorMessage;
    this.stackTrace = stackTrace;
    this.handlerUid = handlerUid;
    this.handledDttm = handledDttm;
  }
}
