package com.ikon.projectmanagement.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.UUID;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "risks")
public class Risks {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Column(name = "risk_identifier", updatable = false, nullable = false)
    private UUID riskIdentifier;

    @Column(name = "risk_title", nullable = false)
    private String riskTitle;

    @Column(name = "risk_probability")
    private Integer riskProbability;

    @Column(name = "gross_risk_value", precision = 15, scale = 2)
    private BigDecimal grossRiskValue;

    @Column(name = "probable_risk_value", precision = 15, scale = 2)
    private BigDecimal probableRiskValue;

    @Column(name = "probable_risk_value_in_usd", precision = 15, scale = 2)
    private BigDecimal probableRiskValueInUSD;

    @Column(name = "risk_impact")
    private String riskImpact;

    @Column(name = "risk_owner")
    private String riskOwner;

    @Column(name = "risk_description", columnDefinition = "TEXT")
    private String riskDescription;

    @Column(name = "financial_risk")
    private Boolean financialRisk;

    @Column(name = "risk_created_date")
    private LocalDateTime riskCreatedDate;

    @Column(name = "risk_options_select_id")
    private String riskOptionsSelectId;

    @Column(name = "risk_status")
    private String riskStatus;

    @Column(name = "risk_age")
    private Integer riskAge;

    @Column(name = "effected_sprint_id")
    private String effectedSprintId;

    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    // @Column(name = "project_identifier", insertable = false, updatable = false)
    // private UUID projectIdentifier;

    @Column(name = "project_identifier")
    private UUID projectIdentifier;

    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
        updatedAt = LocalDateTime.now();
        if (riskCreatedDate == null) {
            riskCreatedDate = LocalDateTime.now();
        }
    }

    @PreUpdate
    protected void onUpdate() {
        updatedAt = LocalDateTime.now();
    }
}