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

import static de.srsoftware.umbrella.core.Util.mapMarkdown;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static java.time.ZoneOffset.UTC;

import de.srsoftware.tools.Mappable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

public record Bookmark(long urlId, String url, String comment, LocalDateTime timestamp, Collection<String> tags) implements Mappable {

	public static Bookmark of(ResultSet rs) throws SQLException {
		return new Bookmark(rs.getLong(ID),rs.getString(URL),rs.getString(COMMENT),LocalDateTime.ofEpochSecond(rs.getLong(TIMESTAMP),0, UTC),new ArrayList<>());
	}

	public static Bookmark of(long urlId, String url, String comment, LocalDateTime timestamp){
		return new Bookmark(urlId,url,comment,timestamp,new ArrayList<>());
	}

	@Override
	public Map<String, Object> toMap() {
		return Map.of(
				ID, urlId,
				URL, url,
				COMMENT, mapMarkdown(comment),
				TAGS, tags,
				TIMESTAMP, timestamp.withNano(0)
		);
	}
}
