package com.goldenchart.entity;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDateTime;

/**
 * 디바이스/유저 × 마켓별 실시간 전략 체크 설정.
 *
 * <ul>
 *   <li>isLiveCheck   — 실시간 체크 ON/OFF</li>
 *   <li>executionType — CANDLE_CLOSE | REALTIME_TICK</li>
 *   <li>strategyId    — 연결된 gc_strategy.id (null 이면 체크 비활성)</li>
 * </ul>
 */
@Entity
@Table(name = "gc_live_strategy_settings")
@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder
public class GcLiveStrategySettings {

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

    @Column(name = "device_id", length = 100)
    private String deviceId;

    @Column(name = "user_id")
    private Long userId;

    @Column(name = "market", nullable = false, length = 30)
    @Builder.Default
    private String market = "KRW-BTC";

    /** 연결된 전략 ID (null = 미연결) */
    @Column(name = "strategy_id")
    private Long strategyId;

    @Column(name = "is_live_check", nullable = false)
    @Builder.Default
    private Boolean isLiveCheck = false;

    /** CANDLE_CLOSE | REALTIME_TICK */
    @Column(name = "execution_type", nullable = false, length = 30)
    @Builder.Default
    private String executionType = "CANDLE_CLOSE";

    /** 전략 평가·데이터 수집 분봉 (1m, 3m, 5m, …) */
    @Column(name = "candle_type", nullable = false, length = 10)
    @Builder.Default
    private String candleType = "1m";

    /** 매도 시그널 포지션 종속성 모드: LONG_ONLY | SIGNAL_ONLY */
    @Column(name = "position_mode", nullable = false, length = 20)
    @Builder.Default
    private String positionMode = "LONG_ONLY";

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

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

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

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