package com.toyshop.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import java.time.LocalDateTime;

@Entity
@Table(name = "addresses")
public class Address {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "user_id", nullable = false)
  @JsonIgnore
  private User user;

  @Column(nullable = false, length = 50)
  private String receiverName;

  @Column(nullable = false, length = 20)
  private String receiverPhone;

  @Column(nullable = false, length = 255)
  private String detail;

  @Column(nullable = false)
  private boolean isDefault = false;

  @Column(nullable = false)
  private LocalDateTime createdAt;

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

  public Long getId() { return id; }
  public void setId(Long id) { this.id = id; }
  public User getUser() { return user; }
  public void setUser(User user) { this.user = user; }
  public String getReceiverName() { return receiverName; }
  public void setReceiverName(String receiverName) { this.receiverName = receiverName; }
  public String getReceiverPhone() { return receiverPhone; }
  public void setReceiverPhone(String receiverPhone) { this.receiverPhone = receiverPhone; }
  public String getDetail() { return detail; }
  public void setDetail(String detail) { this.detail = detail; }
  public boolean isDefault() { return isDefault; }
  public void setDefault(boolean aDefault) { isDefault = aDefault; }
  public LocalDateTime getCreatedAt() { return createdAt; }
}
