// Package main provides the demo-seed source registry.
//
// Sources are deterministically hashed from structured IDs to ensure
// reproducible demo data across runs.
package main

import (
	"crypto/sha256"
	"encoding/hex"

	"github.com/orchard9/stemedb-go/steme"
)

// Source represents a citable evidence source with metadata.
type Source struct {
	// ID is the structured source identifier (e.g., "FDA:Wegovy:Label:2024-01")
	ID string

	// Description is a human-readable source description
	Description string

	// Class is the source authority tier (T0-T5)
	Class steme.SourceClass

	// URL is the source URL (for reference, not used in hashing)
	URL string
}

// Hash returns a deterministic 32-byte hex hash of the source ID.
//
// This ensures the same source always produces the same hash across runs,
// making demo data reproducible.
func (s Source) Hash() string {
	hash := sha256.Sum256([]byte(s.ID))
	return hex.EncodeToString(hash[:])
}

// Sources is the registry of all demo sources.
//
// Organized by source type:
//   - FDA_*: Regulatory sources (Tier 0)
//   - TRIAL_*: Clinical trial sources (Tier 1)
//   - RWE_*: Real-world evidence sources (Tier 2)
//   - EXPERT_*: Expert opinion sources (Tier 3)
//   - COMMUNITY_*: Community sources (Tier 4)
//   - ANECDOTAL_*: Social media sources (Tier 5)
var Sources = map[string]Source{
	// -------------------------------------------------------------------------
	// Tier 0: Regulatory (FDA Labels)
	// -------------------------------------------------------------------------
	"FDA_WEGOVY_LABEL": {
		ID:          "FDA:Wegovy:Label:2024-01",
		Description: "Wegovy (semaglutide) FDA Label, revised January 2024",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2024/215256s024lbl.pdf",
	},
	"FDA_OZEMPIC_LABEL": {
		ID:          "FDA:Ozempic:Label:2024-01",
		Description: "Ozempic (semaglutide) FDA Label for T2D",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2024/209637s020lbl.pdf",
	},
	"FDA_ZEPBOUND_LABEL": {
		ID:          "FDA:Zepbound:Label:2023-11",
		Description: "Zepbound (tirzepatide) FDA Label, approved November 2023",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2023/217806s000lbl.pdf",
	},
	"FDA_MOUNJARO_LABEL": {
		ID:          "FDA:Mounjaro:Label:2024-01",
		Description: "Mounjaro (tirzepatide) FDA Label for T2D",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2024/215866s007lbl.pdf",
	},
	"FDA_SAXENDA_LABEL": {
		ID:          "FDA:Saxenda:Label:2023-07",
		Description: "Saxenda (liraglutide) FDA Label for weight management",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2023/206321s015lbl.pdf",
	},
	"FDA_VICTOZA_LABEL": {
		ID:          "FDA:Victoza:Label:2023-10",
		Description: "Victoza (liraglutide) FDA Label for T2D",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2023/022341s040lbl.pdf",
	},

	// -------------------------------------------------------------------------
	// P2.3: Landmark Study for Cascade Invalidation Demo
	// -------------------------------------------------------------------------
	"CARDIOVASC_MEGA_TRIAL": {
		ID:          "TRIAL:CV-MEGA:NCT99999999:NEJM:2024",
		Description: "CARDIOVASC-MEGA Trial - Landmark multi-drug GLP-1 CV outcomes study, NEJM 2024",
		Class:       steme.SourceClassClinical,
		URL:         "https://example.com/cardiovasc-mega-trial",
	},

	// -------------------------------------------------------------------------
	// Tier 1: Clinical Trials (Peer-Reviewed Publications)
	// -------------------------------------------------------------------------
	"TRIAL_STEP_1": {
		ID:          "TRIAL:STEP1:NCT03548935:NEJM:2021",
		Description: "STEP 1 Trial - Semaglutide 2.4mg vs placebo, NEJM 2021",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.nejm.org/doi/full/10.1056/NEJMoa2032183",
	},
	"TRIAL_STEP_2": {
		ID:          "TRIAL:STEP2:NCT03552757:Lancet:2021",
		Description: "STEP 2 Trial - Semaglutide in T2D patients, Lancet 2021",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.thelancet.com/journals/lancet/article/PIIS0140-6736(21)00213-0/fulltext",
	},
	"TRIAL_STEP_UP": {
		ID:          "TRIAL:STEPUP:7.2mg:2024",
		Description: "STEP UP Trial - Semaglutide 7.2mg higher dose study",
		Class:       steme.SourceClassClinical,
		URL:         "https://clinicaltrials.gov/ct2/show/NCT05813925",
	},
	"TRIAL_SURMOUNT_1": {
		ID:          "TRIAL:SURMOUNT1:NCT04184622:NEJM:2022",
		Description: "SURMOUNT-1 Trial - Tirzepatide vs placebo, NEJM 2022",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.nejm.org/doi/full/10.1056/NEJMoa2206038",
	},
	"TRIAL_SURMOUNT_2": {
		ID:          "TRIAL:SURMOUNT2:NCT04657003:Lancet:2023",
		Description: "SURMOUNT-2 Trial - Tirzepatide in T2D patients, Lancet 2023",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.thelancet.com/journals/lancet/article/PIIS0140-6736(23)01200-X/fulltext",
	},
	"TRIAL_SURMOUNT_3YR": {
		ID:          "TRIAL:SURMOUNT:3YR:ADA:2024",
		Description: "SURMOUNT 3-Year Extension - Long-term tirzepatide data",
		Class:       steme.SourceClassClinical,
		URL:         "https://diabetes.org/newsroom/press-releases/2024/ada-84th-scientific-sessions-surmount",
	},
	"TRIAL_SCALE_OBESITY": {
		ID:          "TRIAL:SCALE:Obesity:NCT01272219:NEJM:2015",
		Description: "SCALE Obesity Trial - Liraglutide 3.0mg, NEJM 2015",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.nejm.org/doi/full/10.1056/NEJMoa1411892",
	},
	"TRIAL_LEADER": {
		ID:          "TRIAL:LEADER:NCT01179048:NEJM:2016",
		Description: "LEADER Trial - Liraglutide CV outcomes, NEJM 2016",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.nejm.org/doi/full/10.1056/NEJMoa1603827",
	},
	"TRIAL_SELECT": {
		ID:          "TRIAL:SELECT:NCT03574597:NEJM:2023",
		Description: "SELECT Trial - Semaglutide CV outcomes in obesity, NEJM 2023",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.nejm.org/doi/full/10.1056/NEJMoa2307563",
	},
	"TRIAL_SUSTAIN_6": {
		ID:          "TRIAL:SUSTAIN6:NCT01720446:NEJM:2016",
		Description: "SUSTAIN-6 Trial - Semaglutide CV outcomes in T2D",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.nejm.org/doi/full/10.1056/NEJMoa1607141",
	},

	// -------------------------------------------------------------------------
	// Tier 2: Real-World Evidence / Observational Studies
	// -------------------------------------------------------------------------
	"RWE_UBC_GASTROPARESIS": {
		ID:          "RWE:UBC:Gastroparesis:JAMA:2023",
		Description: "UBC Study - GLP-1 agonists and gastroparesis risk, JAMA 2023",
		Class:       steme.SourceClassObservational,
		URL:         "https://jamanetwork.com/journals/jama/fullarticle/2809364",
	},
	"RWE_FAERS_SEMAGLUTIDE": {
		ID:          "RWE:FAERS:Semaglutide:2024Q1",
		Description: "FDA FAERS - Semaglutide adverse event reports Q1 2024",
		Class:       steme.SourceClassObservational,
		URL:         "https://www.fda.gov/drugs/questions-and-answers-fdas-adverse-event-reporting-system-faers",
	},
	"RWE_TRINETX_GLP1": {
		ID:          "RWE:TriNetX:GLP1:RealWorld:2024",
		Description: "TriNetX Real-World GLP-1 Outcomes Analysis",
		Class:       steme.SourceClassObservational,
		URL:         "https://trinetx.com/",
	},
	"RWE_OPTUM_TIRZEPATIDE": {
		ID:          "RWE:Optum:Tirzepatide:GI:2024",
		Description: "Optum Labs - Tirzepatide GI side effects real-world data",
		Class:       steme.SourceClassObservational,
		URL:         "https://www.optumlabs.com/",
	},
	"RWE_IQVIA_ADHERENCE": {
		ID:          "RWE:IQVIA:GLP1:Adherence:2024",
		Description: "IQVIA - GLP-1 Adherence and Persistence Real-World Data",
		Class:       steme.SourceClassObservational,
		URL:         "https://www.iqvia.com/",
	},

	// -------------------------------------------------------------------------
	// Tier 3: Expert Opinion / Clinical Guidelines
	// -------------------------------------------------------------------------
	"EXPERT_ADA_GUIDELINES": {
		ID:          "EXPERT:ADA:Standards:2024",
		Description: "ADA Standards of Care in Diabetes 2024",
		Class:       steme.SourceClassExpert,
		URL:         "https://diabetesjournals.org/care/issue/47/Supplement_1",
	},
	"EXPERT_ENDOCRINE_SOCIETY": {
		ID:          "EXPERT:EndocrineSociety:Obesity:2023",
		Description: "Endocrine Society Clinical Practice Guideline on Obesity",
		Class:       steme.SourceClassExpert,
		URL:         "https://academic.oup.com/jcem/article/108/1/9/6798176",
	},
	"EXPERT_ACC_AHA": {
		ID:          "EXPERT:ACC:AHA:CVD:Guidelines:2023",
		Description: "ACC/AHA Cardiovascular Disease Management Guidelines",
		Class:       steme.SourceClassExpert,
		URL:         "https://www.jacc.org/journal/jacc",
	},
	"EXPERT_AACE_OBESITY": {
		ID:          "EXPERT:AACE:Obesity:Algorithm:2023",
		Description: "AACE Obesity Algorithm - Clinical Practice",
		Class:       steme.SourceClassExpert,
		URL:         "https://www.aace.com/",
	},

	// -------------------------------------------------------------------------
	// Tier 4: Curated Community
	// -------------------------------------------------------------------------
	"COMMUNITY_PATIENTS_LIKE_ME": {
		ID:          "COMMUNITY:PatientsLikeMe:GLP1:2024",
		Description: "PatientsLikeMe GLP-1 Community Reports",
		Class:       steme.SourceClassCommunity,
		URL:         "https://www.patientslikeme.com/",
	},
	"COMMUNITY_DIABETES_FORUM": {
		ID:          "COMMUNITY:DiabetesForum:Moderated:2024",
		Description: "Diabetes.co.uk Forum - Moderated Patient Discussions",
		Class:       steme.SourceClassCommunity,
		URL:         "https://www.diabetes.co.uk/forum/",
	},

	// -------------------------------------------------------------------------
	// Tier 5: Anecdotal (Social Media)
	// -------------------------------------------------------------------------
	"ANECDOTAL_REDDIT_OZEMPIC": {
		ID:          "ANECDOTAL:Reddit:r/Ozempic:2024",
		Description: "Reddit r/Ozempic patient experience reports",
		Class:       steme.SourceClassAnecdotal,
		URL:         "https://www.reddit.com/r/Ozempic/",
	},
	"ANECDOTAL_REDDIT_MOUNJARO": {
		ID:          "ANECDOTAL:Reddit:r/Mounjaro:2024",
		Description: "Reddit r/Mounjaro patient experience reports",
		Class:       steme.SourceClassAnecdotal,
		URL:         "https://www.reddit.com/r/Mounjaro/",
	},
	"ANECDOTAL_REDDIT_SAXENDA": {
		ID:          "ANECDOTAL:Reddit:r/liraglutide:2024",
		Description: "Reddit r/liraglutide (Saxenda) patient experiences",
		Class:       steme.SourceClassAnecdotal,
		URL:         "https://www.reddit.com/r/liraglutide/",
	},
	"ANECDOTAL_TWITTER_GLP1": {
		ID:          "ANECDOTAL:Twitter:GLP1:Hashtag:2024",
		Description: "Twitter/X #Ozempic #Mounjaro patient discussions",
		Class:       steme.SourceClassAnecdotal,
		URL:         "https://twitter.com/search?q=%23ozempic",
	},
	"ANECDOTAL_TIKTOK_WEIGHTLOSS": {
		ID:          "ANECDOTAL:TikTok:OzempicJourney:2024",
		Description: "TikTok #OzempicJourney weight loss stories",
		Class:       steme.SourceClassAnecdotal,
		URL:         "https://www.tiktok.com/tag/ozempicjourney",
	},

	// -------------------------------------------------------------------------
	// P2.4: Historical Sources (FDA Label Versions Over Time)
	// These enable time-travel demos showing how knowledge evolved
	// -------------------------------------------------------------------------

	// Wegovy label history (CV indication added March 2024)
	"FDA_WEGOVY_LABEL_2021": {
		ID:          "FDA:Wegovy:Label:2021-06",
		Description: "Wegovy (semaglutide) FDA Label, initial approval June 2021 (no CV indication)",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2021/215256s000lbl.pdf",
	},
	"FDA_WEGOVY_LABEL_2024_CV": {
		ID:          "FDA:Wegovy:Label:2024-03:CV",
		Description: "Wegovy (semaglutide) FDA Label, March 2024 revision (CV risk reduction added)",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2024/215256s024lbl.pdf",
	},

	// Ozempic label history (MTC warning evolution)
	"FDA_OZEMPIC_LABEL_2017": {
		ID:          "FDA:Ozempic:Label:2017-12",
		Description: "Ozempic (semaglutide) FDA Label, initial approval December 2017",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2017/209637s000lbl.pdf",
	},

	// Mounjaro/Zepbound evolution (T2D then obesity)
	"FDA_MOUNJARO_LABEL_2022": {
		ID:          "FDA:Mounjaro:Label:2022-05",
		Description: "Mounjaro (tirzepatide) FDA Label, initial T2D approval May 2022",
		Class:       steme.SourceClassRegulatory,
		URL:         "https://www.accessdata.fda.gov/drugsatfda_docs/label/2022/215866s000lbl.pdf",
	},

	// SELECT trial interim vs final (knowledge evolution)
	"TRIAL_SELECT_INTERIM": {
		ID:          "TRIAL:SELECT:NCT03574597:Interim:2022",
		Description: "SELECT Trial Interim Analysis - Early CV signal (not yet published)",
		Class:       steme.SourceClassClinical,
		URL:         "https://clinicaltrials.gov/ct2/show/NCT03574597",
	},
	"TRIAL_SELECT_FINAL": {
		ID:          "TRIAL:SELECT:NCT03574597:NEJM:2023-11",
		Description: "SELECT Trial Final Results - Semaglutide CV outcomes, NEJM November 2023",
		Class:       steme.SourceClassClinical,
		URL:         "https://www.nejm.org/doi/full/10.1056/NEJMoa2307563",
	},

	// ADA guidelines evolution
	"EXPERT_ADA_GUIDELINES_2023": {
		ID:          "EXPERT:ADA:Standards:2023",
		Description: "ADA Standards of Care in Diabetes 2023 (pre-SELECT)",
		Class:       steme.SourceClassExpert,
		URL:         "https://diabetesjournals.org/care/issue/46/Supplement_1",
	},
	"EXPERT_ADA_GUIDELINES_2024": {
		ID:          "EXPERT:ADA:Standards:2024",
		Description: "ADA Standards of Care in Diabetes 2024 (post-SELECT, GLP-1 prioritized for CV)",
		Class:       steme.SourceClassExpert,
		URL:         "https://diabetesjournals.org/care/issue/47/Supplement_1",
	},
}
