package online.wesal.wesal.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

@Entity
@Table(name = "invitation_codes")
public class InvitationCode {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(unique = true, nullable = false)
    @NotBlank
    @Size(max = 200)
    private String code;
    
    @Column(nullable = false)
    private LocalDateTime expirationDate;
    
    @Column(nullable = false)
    private LocalDateTime createdDate;
    
    public InvitationCode() {
        this.createdDate = LocalDateTime.now();
        this.expirationDate = LocalDateTime.now().plusDays(30);
    }
    
    public InvitationCode(String code) {
        this();
        this.code = code;
    }
    
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getCode() {
        return code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    public LocalDateTime getExpirationDate() {
        return expirationDate;
    }
    
    public void setExpirationDate(LocalDateTime expirationDate) {
        this.expirationDate = expirationDate;
    }
    
    public LocalDateTime getCreatedDate() {
        return createdDate;
    }
    
    public void setCreatedDate(LocalDateTime createdDate) {
        this.createdDate = createdDate;
    }
    
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(this.expirationDate);
    }
}