package com.oguerreiro.resilient.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.oguerreiro.resilient.domain.enumeration.ContentPageType;
import com.oguerreiro.resilient.security.custom.ResilientSecurityResourceConfig;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;

/**
 * ContentPage
 * Defines a HTML page content.
 */
@Entity
@Table(name = "content_page")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@ResilientSecurityResourceConfig()
public class ContentPage extends AbstractResilientLongIdEntity<ContentPage> {

  private static final long serialVersionUID = 1L;

  @NotNull
  @Column(name = "title", nullable = false)
  private String title;

  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "slug", nullable = false, unique = true)
  private ContentPageType slug;

  @NotNull
  @Lob
  @Column(name = "html_content", nullable = false)
  private String content;

  public String getTitle() {
    return title;
  }

  public ContentPage title(String title) {
    this.setTitle(title);
    return this;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public ContentPageType getSlug() {
    return slug;
  }

  public ContentPage slug(ContentPageType slug) {
    this.setSlug(slug);
    return this;
  }

  public void setSlug(ContentPageType slug) {
    this.slug = slug;
  }

  public String getContent() {
    return content;
  }

  public ContentPage slug(String content) {
    this.setContent(content);
    return this;
  }

  public void setContent(String content) {
    this.content = content;
  }

  //@formatter:off
  @Override
  public String toString() {
    return "ContentPage{" + 
              "id=" + getId() + 
              ", title='" + getTitle() + "'" + 
              ", slug='" + getSlug() + "'" +
              ", version=" + getVersion() + 
           "}";
  }
  //@formatter:on
}
