package de.oaa.xxx.emailchange;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.UUID;

@Getter
@Setter
@Entity
@Table(name = "email_change")
public class EmailChangeEntity {

    @Id
    @Column
    private UUID tokenId;

    @Column
    private String userEmail;

    @Column
    private String newEmail;

    @Column
    private LocalDateTime createdAt;

    @Override
    public String toString() {
        return "EmailChangeEntity[tokenId=" + tokenId + ", userEmail=" + userEmail + ", newEmail=" + newEmail + ", createdAt=" + createdAt + "]";
    }

    public static EmailChangeEntity create(String userEmail, String newEmail) {
        EmailChangeEntity entity = new EmailChangeEntity();
        entity.setTokenId(UUID.randomUUID());
        entity.setUserEmail(userEmail);
        entity.setNewEmail(newEmail);
        entity.setCreatedAt(LocalDateTime.now());
        return entity;
    }
}
