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 ("LTR", "Letter Template");
INSERT INTO "Ref_Template_Types" VALUES ("MEM", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("AGR", "Agreement Template");
INSERT INTO "Templates" VALUES ("101", "INV");
INSERT INTO "Templates" VALUES ("102", "REP");
INSERT INTO "Templates" VALUES ("103", "LTR");
INSERT INTO "Templates" VALUES ("104", "MEM");
INSERT INTO "Templates" VALUES ("105", "INV");
INSERT INTO "Templates" VALUES ("106", "REP");
INSERT INTO "Templates" VALUES ("107", "LTR");
INSERT INTO "Templates" VALUES ("108", "AGR");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_2023_001");
INSERT INTO "Documents" VALUES ("2", "101", "Invoice_2023_002");
INSERT INTO "Documents" VALUES ("3", "102", "Monthly_Report_Q1");
INSERT INTO "Documents" VALUES ("4", "103", "Client_Letter_A");
INSERT INTO "Documents" VALUES ("5", "101", "Invoice_2023_003");
INSERT INTO "Documents" VALUES ("6", "104", "Internal_Memo_Project_X");
INSERT INTO "Documents" VALUES ("7", "102", "Annual_Report_2022");
INSERT INTO "Documents" VALUES ("8", "101", "Invoice_2023_004");
INSERT INTO "Documents" VALUES ("9", "103", "Client_Letter_B");
INSERT INTO "Documents" VALUES ("10", "105", "Invoice_2023_005");
INSERT INTO "Documents" VALUES ("11", "105", "Invoice_2023_006");
INSERT INTO "Documents" VALUES ("12", "106", "Quarterly_Report_Q2");
INSERT INTO "Documents" VALUES ("13", "107", "Supplier_Letter_C");
INSERT INTO "Documents" VALUES ("14", "108", "Service_Agreement_V1");
INSERT INTO "Documents" VALUES ("15", "101", "Invoice_2023_007");
INSERT INTO "Paragraphs" VALUES ("1", "This is the first paragraph of document 1.");
INSERT INTO "Paragraphs" VALUES ("2", "This is the second paragraph of document 1.");
INSERT INTO "Paragraphs" VALUES ("3", "Report summary for Q1.");
INSERT INTO "Paragraphs" VALUES ("4", "Dear Client, we are writing to inform you...");
INSERT INTO "Paragraphs" VALUES ("5", "Invoice details for transaction 003.");
INSERT INTO "Paragraphs" VALUES ("6", "Memo regarding project X status.");
INSERT INTO "Paragraphs" VALUES ("7", "Annual report highlights.");
INSERT INTO "Paragraphs" VALUES ("8", "Payment due for invoice 004.");
INSERT INTO "Paragraphs" VALUES ("9", "Follow-up letter to client B.");
INSERT INTO "Paragraphs" VALUES ("10", "Invoice for services rendered.");