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 "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 ("TYPE_A", "Invoice Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Contract Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "Presentation Template");
INSERT INTO "Templates" VALUES ("101", "TYPE_A", "Standard invoice layout with company logo");
INSERT INTO "Templates" VALUES ("102", "TYPE_B", "Monthly financial report format");
INSERT INTO "Templates" VALUES ("103", "TYPE_C", "Legal contract template with clauses");
INSERT INTO "Templates" VALUES ("104", "TYPE_D", "Internal memo format with header");
INSERT INTO "Templates" VALUES ("105", "TYPE_E", "Sales presentation slides template");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_2023_001");
INSERT INTO "Documents" VALUES ("2", "101", "Invoice_2023_002");
INSERT INTO "Documents" VALUES ("3", "101", "Invoice_2023_003");
INSERT INTO "Documents" VALUES ("4", "102", "Report_Jan_2023");
INSERT INTO "Documents" VALUES ("5", "102", "Report_Feb_2023");
INSERT INTO "Documents" VALUES ("6", "103", "Contract_ClientA");
INSERT INTO "Documents" VALUES ("7", "103", "Contract_ClientB");
INSERT INTO "Documents" VALUES ("8", "103", "Contract_ClientC");
INSERT INTO "Documents" VALUES ("9", "103", "Contract_ClientD");
INSERT INTO "Documents" VALUES ("10", "104", "Memo_StaffMeeting");
INSERT INTO "Documents" VALUES ("11", "105", "Sales_Presentation_Q1");
INSERT INTO "Documents" VALUES ("12", "101", "Invoice_2023_004");
INSERT INTO "Documents" VALUES ("13", "101", "Invoice_2023_005");
INSERT INTO "Documents" VALUES ("14", "103", "Contract_ClientE");
INSERT INTO "Documents" VALUES ("15", "103", "Contract_ClientF");
INSERT INTO "Documents" VALUES ("16", "103", "Contract_ClientG");
INSERT INTO "Documents" VALUES ("17", "103", "Contract_ClientH");
INSERT INTO "Documents" VALUES ("18", "103", "Contract_ClientI");
INSERT INTO "Documents" VALUES ("19", "103", "Contract_ClientJ");
INSERT INTO "Documents" VALUES ("20", "104", "Memo_ProjectUpdate");