package com.goldenchart.entity;

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

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

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

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

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

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

    @Column(name = "symbol", nullable = false, length = 30)
    private String symbol;

    @Column(name = "side", nullable = false, length = 8)
    private String side;

    @Column(name = "order_kind", nullable = false, length = 16)
    @Builder.Default
    private String orderKind = "market";

    @Column(name = "source", nullable = false, length = 32)
    @Builder.Default
    private String source = "STRATEGY";

    @Column(name = "strategy_id")
    private Long strategyId;

    @Column(name = "upbit_order_uuid", length = 64)
    private String upbitOrderUuid;

    @Column(name = "price", nullable = false, precision = 20, scale = 8)
    private BigDecimal price;

    @Column(name = "quantity", nullable = false, precision = 24, scale = 12)
    private BigDecimal quantity;

    @Column(name = "gross_amount", nullable = false, precision = 20, scale = 2)
    private BigDecimal grossAmount;

    @Column(name = "fee_amount", precision = 20, scale = 2)
    private BigDecimal feeAmount;

    @Column(name = "state", nullable = false, length = 24)
    @Builder.Default
    private String state = "done";

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

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