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,
"Document_ID" INT,
PRIMARY KEY ("Paragraph_ID"),
FOREIGN KEY ("Document_ID") REFERENCES "Documents"("Document_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),
"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 ("FORM", "Standard Form Template");
INSERT INTO "Ref_Template_Types" VALUES ("REPORT", "Report Generation Template");
INSERT INTO "Ref_Template_Types" VALUES ("LETTER", "Official Letter Template");
INSERT INTO "Ref_Template_Types" VALUES ("MEMO", "Internal Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("CONTRACT", "Legal Contract Template");
INSERT INTO "Templates" VALUES ("101", "FORM", "Application Form v1.0");
INSERT INTO "Templates" VALUES ("102", "REPORT", "Monthly Sales Report");
INSERT INTO "Templates" VALUES ("103", "LETTER", "Official Correspondence");
INSERT INTO "Templates" VALUES ("104", "MEMO", "Internal Communication Memo");
INSERT INTO "Templates" VALUES ("105", "CONTRACT", "Service Agreement Template");
INSERT INTO "Templates" VALUES ("106", "FORM", "Feedback Survey v2.0");
INSERT INTO "Templates" VALUES ("107", "REPORT", "Annual Financial Report");
INSERT INTO "Documents" VALUES ("1", "101", "New Client Application");
INSERT INTO "Documents" VALUES ("2", "102", "Q3 Sales Performance");
INSERT INTO "Documents" VALUES ("3", "103", "Welcome Letter to New Employee");
INSERT INTO "Documents" VALUES ("4", "104", "Meeting Minutes 2023-10-26");
INSERT INTO "Documents" VALUES ("5", "105", "Software License Agreement");
INSERT INTO "Documents" VALUES ("6", "101", "Data base");
INSERT INTO "Documents" VALUES ("7", "106", "Customer Satisfaction Survey");
INSERT INTO "Documents" VALUES ("8", "102", "Data base");
INSERT INTO "Documents" VALUES ("9", "107", "2023 Annual Report");
INSERT INTO "Documents" VALUES ("10", "103", "Follow-up Letter");
INSERT INTO "Paragraphs" VALUES ("1001", "1");
INSERT INTO "Paragraphs" VALUES ("1002", "1");
INSERT INTO "Paragraphs" VALUES ("1003", "2");
INSERT INTO "Paragraphs" VALUES ("1004", "3");
INSERT INTO "Paragraphs" VALUES ("1005", "4");
INSERT INTO "Paragraphs" VALUES ("1006", "5");
INSERT INTO "Paragraphs" VALUES ("1007", "6");
INSERT INTO "Paragraphs" VALUES ("1008", "6");
INSERT INTO "Paragraphs" VALUES ("1009", "7");
INSERT INTO "Paragraphs" VALUES ("1010", "8");
INSERT INTO "Paragraphs" VALUES ("1011", "9");
INSERT INTO "Paragraphs" VALUES ("1012", "10");