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 ("TT001", "Standard Business Template");
INSERT INTO "Ref_Template_Types" VALUES ("TT002", "Technical Documentation");
INSERT INTO "Ref_Template_Types" VALUES ("TT003", "Legal Agreement Template");
INSERT INTO "Ref_Template_Types" VALUES ("TT004", "Marketing Brochure Template");
INSERT INTO "Ref_Template_Types" VALUES ("TT005", "Database Design Template");
INSERT INTO "Templates" VALUES ("101", "TT001", "Basic business letter format");
INSERT INTO "Templates" VALUES ("102", "TT002", "API technical specification layout");
INSERT INTO "Templates" VALUES ("103", "TT003", "Contract agreement format");
INSERT INTO "Templates" VALUES ("104", "TT004", "Product marketing brochure");
INSERT INTO "Templates" VALUES ("105", "TT005", "Database schema and ER diagram template");
INSERT INTO "Templates" VALUES ("106", "TT005", "Advanced database design template with normalization");
INSERT INTO "Documents" VALUES ("201", "101", "Welcome Letter");
INSERT INTO "Documents" VALUES ("202", "105", "Data base");
INSERT INTO "Documents" VALUES ("203", "103", "Service Contract");
INSERT INTO "Documents" VALUES ("204", "104", "Summer Campaign");
INSERT INTO "Documents" VALUES ("205", "106", "Data base Advanced");
INSERT INTO "Documents" VALUES ("206", "102", "API Guide");
INSERT INTO "Paragraphs" VALUES ("301", "This document outlines the basic business letter format.");
INSERT INTO "Paragraphs" VALUES ("302", "Technical specifications for the API are detailed here.");
INSERT INTO "Paragraphs" VALUES ("303", "This contract is legally binding between parties.");
INSERT INTO "Paragraphs" VALUES ("304", "Marketing brochure for the new product launch.");
INSERT INTO "Paragraphs" VALUES ("305", "Database schema includes tables, keys, and relationships.");
INSERT INTO "Paragraphs" VALUES ("306", "Advanced normalization techniques are applied in this template.");