package com.goldenchart.entity;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

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

@Entity
@Table(name = "gc_backtest_result")
@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder
public class GcBacktestResult {

    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "device_id",   length = 100) private String deviceId;
    @Column(name = "strategy_id")               private Long   strategyId;
    @Column(name = "strategy_name", length = 200) private String strategyName;
    @Column(name = "symbol",      length = 50)  private String symbol;
    @Column(name = "timeframe",   length = 10)  private String timeframe;
    @Column(name = "bar_count")                 private Integer barCount;
    @Column(name = "from_time")                 private Long   fromTime;
    @Column(name = "to_time")                   private Long   toTime;

    @Column(name = "settings_json", columnDefinition = "JSON")
    @JdbcTypeCode(SqlTypes.JSON) private String settingsJson;

    @Column(name = "signals_json",  columnDefinition = "JSON")
    @JdbcTypeCode(SqlTypes.JSON) private String signalsJson;

    @Column(name = "analysis_json", columnDefinition = "JSON")
    @JdbcTypeCode(SqlTypes.JSON) private String analysisJson;

    @Column(name = "total_return",  precision = 12, scale = 4) private BigDecimal totalReturn;
    @Column(name = "win_rate",      precision = 6,  scale = 4) private BigDecimal winRate;
    @Column(name = "total_trades")                             private Integer    totalTrades;
    @Column(name = "max_drawdown",  precision = 12, scale = 4) private BigDecimal maxDrawdown;
    @Column(name = "sharpe_ratio",  precision = 10, scale = 4) private BigDecimal sharpeRatio;
    @Column(name = "final_equity",  precision = 20, scale = 2) private BigDecimal finalEquity;

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

    @PrePersist protected void onCreate() { createdAt = LocalDateTime.now(); }
}
