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 "Templates" VALUES ("101", "INV");
INSERT INTO "Templates" VALUES ("102", "REP");
INSERT INTO "Templates" VALUES ("103", "MEM");
INSERT INTO "Templates" VALUES ("104", "INV");
INSERT INTO "Templates" VALUES ("105", "AGR");
INSERT INTO "Templates" VALUES ("106", "REP");
INSERT INTO "Templates" VALUES ("107", "INV");
INSERT INTO "Templates" VALUES ("108", "LTR");
INSERT INTO "Templates" VALUES ("109", "INV");
INSERT INTO "Templates" VALUES ("110", "MEM");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_001");
INSERT INTO "Documents" VALUES ("2", "102", "Monthly_Report_Q1");
INSERT INTO "Documents" VALUES ("3", "103", "Internal_Memo_HR");
INSERT INTO "Documents" VALUES ("4", "104", "Invoice_002");
INSERT INTO "Documents" VALUES ("5", "105", "Service_Agreement_A");
INSERT INTO "Documents" VALUES ("6", "106", "Annual_Report_2023");
INSERT INTO "Documents" VALUES ("7", "107", "Invoice_003");
INSERT INTO "Documents" VALUES ("8", "101", "Invoice_004");
INSERT INTO "Documents" VALUES ("9", "108", "Client_Letter_XYZ");
INSERT INTO "Documents" VALUES ("10", "109", "Invoice_005");
INSERT INTO "Documents" VALUES ("11", "103", "Memo_Marketing_Campaign");
INSERT INTO "Documents" VALUES ("12", "102", "Sales_Report_March");
INSERT INTO "Documents" VALUES ("13", "101", "Invoice_006");
INSERT INTO "Documents" VALUES ("14", "104", "Invoice_007");
INSERT INTO "Documents" VALUES ("15", "105", "Partnership_Agreement_B");
INSERT INTO "Paragraphs" VALUES ("1", "This is the first paragraph of the document.");
INSERT INTO "Paragraphs" VALUES ("2", "Second paragraph with some details.");
INSERT INTO "Paragraphs" VALUES ("3", "Concluding remarks for the report.");
INSERT INTO "Paragraphs" VALUES ("4", "Important notice regarding the new policy.");
INSERT INTO "Paragraphs" VALUES ("5", "Terms and conditions apply.");
INSERT INTO "Paragraphs" VALUES ("6", "Summary of findings.");
INSERT INTO "Paragraphs" VALUES ("7", "Payment due upon receipt.");
INSERT INTO "Paragraphs" VALUES ("8", "Confidential information.");
INSERT INTO "Paragraphs" VALUES ("9", "Sincerely, Management.");
INSERT INTO "Paragraphs" VALUES ("10", "Thank you for your business.");