package de.champonthis.buntspecht.model;

import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;

@Entity
@Table(name = "users")
@JsonInclude(Include.NON_EMPTY)
public class User {

	@Id
	@Column(name = "username", nullable = false)
	private String username;
	@Column(name = "external_id", nullable = true)
	private String externalId;
	@Column(name = "name", nullable = true)
	private String name;
	@JsonIgnore
	@Column(name = "password_hash", nullable = true)
	private String passwordHash;
	@ElementCollection(fetch = FetchType.EAGER)
	@CollectionTable(name = "users_roles")
	private List<String> roles;
	@Lob
	@Column(name = "about", nullable = true, length = 100000)
	private String about;
	@Column(name = "email", nullable = true)
	private String email;
	@Column(name = "locale", nullable = true, columnDefinition = "varchar(255) default 'de'")
	private String locale;
	@Column(name = "dark_theme", nullable = true, columnDefinition = "boolean default false")
	private boolean darkTheme;
	@Transient
	private Map<String, Object> metadata;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getExternalId() {
		return externalId;
	}

	public void setExternalId(String externalId) {
		this.externalId = externalId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPasswordHash() {
		return passwordHash;
	}

	public void setPasswordHash(String passwordHash) {
		this.passwordHash = passwordHash;
	}

	public List<String> getRoles() {
		return roles;
	}

	public void setRoles(List<String> roles) {
		this.roles = roles;
	}

	public String getAbout() {
		return about;
	}

	public void setAbout(String about) {
		this.about = about;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getLocale() {
		return locale;
	}

	public void setLocale(String locale) {
		this.locale = locale;
	}

	public boolean isDarkTheme() {
		return darkTheme;
	}

	public void setDarkTheme(boolean darkTheme) {
		this.darkTheme = darkTheme;
	}

	public Map<String, Object> getMetadata() {
		if (metadata == null) {
			metadata = Map.of();
		}
		return metadata;
	}

	public void setMetadata(Map<String, Object> metadata) {
		this.metadata = metadata;
	}

}
