package com.goldenchart.entity;

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

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

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

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

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

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

    @Column(name = "cash_balance", precision = 20, scale = 2, nullable = false)
    @Builder.Default
    private BigDecimal cashBalance = BigDecimal.valueOf(10_000_000);

    @Column(name = "realized_pnl", precision = 20, scale = 2, nullable = false)
    @Builder.Default
    private BigDecimal realizedPnl = BigDecimal.ZERO;

    @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();
    }
}
