package com.codenetworkz.blog.models;

import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;


@Getter
@Setter
@Entity
public class Comment extends BaseModel {

    @Size(min = 3, max = 50, message = "Name should be more then 3 and less then 50 character required.")
    private String author;

    @Column(length = 1, nullable = false)
    private Status isEdited;

    @Lob
    private String message;

    @OneToOne(fetch = FetchType.LAZY)
    private Post post;

    public Comment() {
        super();
    }


    @PrePersist
    protected void onCreate() {
        if (super.getCreateAt() == null) {
            setCreateAt(LocalDateTime.now());
        }
        if (super.getIsDelete() == null) {
            setIsDelete(Status.NO);
        }

        if (super.getIsActive() == null) {
            setIsActive(Status.YES);
        }

    }

}