import { co, CoMap, Encoders } from "jazz-tools"
import { GlobalTopic } from "./global-topic.old"

// GlobalLinkAiSummary is high quality title, description, summary of link (generated by AI)
export class GlobalLinkAiSummary extends CoMap {
	link = co.ref(GlobalLink) // link the summary is for
	aiModelUsed = co.string // model used to generate summary, e.g. "gpt-4o"
	title = co.string // high quality title of link
	description = co.string // high quality description of link
	summary = co.string // high quality summary of link
	// vectorContent = co.optional.vector // vector content of link, TODO: jazz needs support for this
}

// GlobalLinkSummary is high quality title, description, summary of link
export class GlobalLinkSummary extends CoMap {
	link = co.ref(GlobalLink) // link the summary is for
	title = co.string // high quality title of link
	description = co.string // high quality description of link
	summary = co.string // high quality summary of link
}

// GlobalLink is link with unique URL that holds some useful metadata. Can be used to do queries like `most popular links added by users` etc.
export class GlobalLink extends CoMap {
	url = co.string // url without the protocol (e.g. "learn-anything.xyz") (unique)
	urlTitle = co.string // title of the page (as grabbed from url itself)
	protocol = co.literal("https") // TODO: other protocols? perhaps should be `co.string` for user custom protocols?
	aiSummary = co.optional.ref(GlobalLinkAiSummary) // TODO: should probably be a list? with allowing users to vote on results so 'top' one can be shown too
	summary = co.optional.ref(GlobalLinkSummary) // the very 'best' summary of link (can be part AI generated, part human written, whatever is best)
	urlWasCreatedOnInternetAt = co.optional.encoded(Encoders.Date) // date url was created on internet at (can pass just year or year+month or year+month+day)
	globalMainTopic = co.optional.ref(GlobalTopic) // each global link can have one main topic (to closest approximation)
	public = co.optional.boolean // if true, link is accessible from global search
	processed = co.optional.encoded(Encoders.Date) // date link was processed at by LA (update metadata etc.)
	// websiteDown = co.boolean // if website is 404 or down TODO: add it later when we have service to check for dead links
}
