package com.lanyuanxiaoyao.leopard.core.entity;

import com.lanyuanxiaoyao.leopard.core.Constants;
import com.lanyuanxiaoyao.service.template.entity.SimpleEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDate;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Setter
@Getter
@ToString(callSuper = true)
@FieldNameConstants
@Entity
@DynamicUpdate
@DynamicInsert
@EntityListeners(AuditingEntityListener.class)
@Table(name = Constants.DATABASE_PREFIX + "daily")
public class Daily extends SimpleEntity {
  @Column(nullable = false)
  @Comment("交易日")
  private LocalDate tradeDate;
  @Comment("开盘价")
  private Double open;
  @Comment("最高价")
  private Double high;
  @Comment("最低价")
  private Double low;
  @Comment("收盘价")
  private Double close;
  @Comment("昨收价")
  private Double previousClose;
  @Comment("涨跌额")
  private Double priceChangeAmount;
  @Comment("涨跌幅")
  private Double priceFluctuationRange;
  @Comment("成交量")
  private Double volume;
  @Comment("成交额")
  private Double turnover;
  @Comment("除权因子")
  private Double factor;

  @ManyToOne
  @JoinColumn(nullable = false)
  @ToString.Exclude
  private Stock stock;

  public Double getHfqOpen() {
    return open * factor;
  }

  public Double getHfqClose() {
    return close * factor;
  }

  public Double getHfqHigh() {
    return high * factor;
  }

  public Double getHfqLow() {
    return low * factor;
  }
}
