/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;


import static de.srsoftware.umbrella.core.constants.Field.*;

import de.srsoftware.tools.Mappable;
import de.srsoftware.umbrella.core.api.Owner;
import de.srsoftware.umbrella.core.constants.Module;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/* © SRSoftware 2025 */
public class UmbrellaUser extends User implements Mappable, Owner {

	private final long id;
	private final String theme;

	public UmbrellaUser(long id, String name, EmailAddress email, String theme, String languageCode)  {
		super(name, email, languageCode);
		this.id = id;
		this.theme = theme;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof UmbrellaUser user) {
			return Objects.equals(email(), user.email())
					&& Objects.equals(name(), user.name())
					&& Objects.equals(id, user.id)
					&& Objects.equals(language(), user.language());
		}
		if (o instanceof User user) return user.equals(this);
		return false;
	}

	@Override
	public int hashCode() {
		return Objects.hash(email(), id, language(), name());
	}

	public long id(){
		return id;
	}

	@Override
	public Owner resolve() {
		return this;
	}

	public String theme(){
		return theme;
	}

	@Override
	public Map<String,Object> toMap() {
		var map = new HashMap<String,Object>();
		map.put(ID,id);
		map.put(LOGIN, name()); // this is still used by old umbrella modules
		map.put(NAME, name());
		map.put(EMAIL,email() instanceof EmailAddress ea ? ea.toString() : null);
		map.put(THEME,theme);
		map.put(LANGUAGE,language());
		return map;
	}

	@Override
	public String type() {
		return Module.USER;
	}
}
