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,
"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),
"Template_Type_Description" VARCHAR(255),
PRIMARY KEY ("Template_Type_Code")
);

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





INSERT INTO "Ref_Template_Types" VALUES ("BK", "Book Template");
INSERT INTO "Ref_Template_Types" VALUES ("AR", "Article Template");
INSERT INTO "Ref_Template_Types" VALUES ("RP", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("MN", "Manual Template");
INSERT INTO "Ref_Template_Types" VALUES ("BK_SPECIAL", "Special Book Template");
INSERT INTO "Templates" VALUES ("1", "BK", "Standard book template with chapters and index");
INSERT INTO "Templates" VALUES ("2", "AR", "Scientific article template with abstract and references");
INSERT INTO "Templates" VALUES ("3", "RP", "Annual report template with financial summary");
INSERT INTO "Templates" VALUES ("4", "MN", "User manual template with troubleshooting section");
INSERT INTO "Templates" VALUES ("5", "BK", "Children book template with illustrations");
INSERT INTO "Templates" VALUES ("6", "BK_SPECIAL", "Limited edition book template with special cover");
INSERT INTO "Documents" VALUES ("101", "1", "History of Ancient Rome");
INSERT INTO "Documents" VALUES ("102", "2", "Advances in Quantum Computing");
INSERT INTO "Documents" VALUES ("103", "3", "2023 Financial Report");
INSERT INTO "Documents" VALUES ("104", "4", "Smartphone User Guide");
INSERT INTO "Documents" VALUES ("105", "5", "Fairy Tales for Kids");
INSERT INTO "Documents" VALUES ("106", "6", "Collectors Edition: Classic Novels");
INSERT INTO "Documents" VALUES ("107", "3", "Midyear Financial Summary");
INSERT INTO "Documents" VALUES ("108", "1", "Modern European History");
INSERT INTO "Documents" VALUES ("109", "2", "Medical Research Findings");
INSERT INTO "Documents" VALUES ("110", "5", "Bedtime Stories");
INSERT INTO "Paragraphs" VALUES ("201", "Introduction to the document");
INSERT INTO "Paragraphs" VALUES ("202", "Summary of key points");
INSERT INTO "Paragraphs" VALUES ("203", "Detailed analysis and discussion");
INSERT INTO "Paragraphs" VALUES ("204", "Conclusion and future work");
INSERT INTO "Paragraphs" VALUES ("205", "References and bibliography");
INSERT INTO "Paragraphs" VALUES ("206", "Appendix with additional data");
INSERT INTO "Paragraphs" VALUES ("207", "Illustrations and figures");
INSERT INTO "Paragraphs" VALUES ("208", "Preface and acknowledgments");
INSERT INTO "Paragraphs" VALUES ("209", "Table of contents");
INSERT INTO "Paragraphs" VALUES ("210", "Glossary of terms");