PRAGMA foreign_keys = ON;

PRAGMA writable_schema = 1;
DELETE FROM sqlite_master WHERE type IN ("table", "index", "trigger");
PRAGMA writable_schema = 0;
VACUUM;

CREATE TABLE "Documents" (
"Document_ID" INT UNIQUE,
"Template_ID" INT,
"Document_Name" VARCHAR(255),
PRIMARY KEY ("Document_ID"),
FOREIGN KEY ("Template_ID") REFERENCES "Templates"("Template_ID")
);

CREATE TABLE "Paragraphs" (
"Paragraph_ID" INT,
"Paragraph_Text" VARCHAR(255),
PRIMARY KEY ("Paragraph_ID")
);

CREATE TABLE "Ref_Template_Types" (
"Template_Type_Code" CHAR(15) UNIQUE,
"Template_Type_Description" VARCHAR(255),
PRIMARY KEY ("Template_Type_Code")
);

CREATE TABLE "Templates" (
"Template_ID" INT UNIQUE,
"Template_Type_Code" CHAR(15),
PRIMARY KEY ("Template_ID"),
FOREIGN KEY ("Template_Type_Code") REFERENCES "Ref_Template_Types"("Template_Type_Code")
);





INSERT INTO "Ref_Template_Types" VALUES ("INV", "Invoice Template");
INSERT INTO "Ref_Template_Types" VALUES ("REP", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("MEM", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("AGR", "Agreement Template");
INSERT INTO "Ref_Template_Types" VALUES ("LTR", "Letter Template");
INSERT INTO "Ref_Template_Types" VALUES ("PRO", "Proposal Template");
INSERT INTO "Ref_Template_Types" VALUES ("REC", "Receipt Template");
INSERT INTO "Templates" VALUES ("101", "INV");
INSERT INTO "Templates" VALUES ("102", "REP");
INSERT INTO "Templates" VALUES ("103", "MEM");
INSERT INTO "Templates" VALUES ("104", "AGR");
INSERT INTO "Templates" VALUES ("105", "LTR");
INSERT INTO "Templates" VALUES ("106", "PRO");
INSERT INTO "Templates" VALUES ("107", "INV");
INSERT INTO "Templates" VALUES ("108", "REP");
INSERT INTO "Templates" VALUES ("109", "MEM");
INSERT INTO "Templates" VALUES ("110", "REC");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_2023_001");
INSERT INTO "Documents" VALUES ("2", "102", "Annual_Report_Q1");
INSERT INTO "Documents" VALUES ("3", "103", "Meeting_Minutes_05_10");
INSERT INTO "Documents" VALUES ("4", "104", "Service_Agreement_ClientA");
INSERT INTO "Documents" VALUES ("5", "105", "Welcome_Letter_New_Hire");
INSERT INTO "Documents" VALUES ("6", "101", "Invoice_2023_002");
INSERT INTO "Documents" VALUES ("7", "102", "Monthly_Report_Sales");
INSERT INTO "Documents" VALUES ("8", "103", "Internal_Memo_ProjectX");
INSERT INTO "Documents" VALUES ("9", "104", "Partnership_Agreement_B");
INSERT INTO "Documents" VALUES ("10", "105", "Follow_Up_Letter_ClientC");
INSERT INTO "Documents" VALUES ("11", "107", "Invoice_2023_003");
INSERT INTO "Documents" VALUES ("12", "108", "Quarterly_Report_Finance");
INSERT INTO "Paragraphs" VALUES ("1", "This is the first paragraph of the document.");
INSERT INTO "Paragraphs" VALUES ("2", "The second paragraph contains important details.");
INSERT INTO "Paragraphs" VALUES ("3", "A concluding paragraph summarizes the content.");
INSERT INTO "Paragraphs" VALUES ("4", "Additional information can be found in the appendix.");
INSERT INTO "Paragraphs" VALUES ("5", "This paragraph is part of a different document.");