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", "Newsletter 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 signature fields");
INSERT INTO "Templates" VALUES ("104", "TYPE_D", "Internal memo template with header and footer");
INSERT INTO "Templates" VALUES ("105", "TYPE_E", "Monthly newsletter template with images");
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_ABC_Corp");
INSERT INTO "Documents" VALUES ("7", "103", "Contract_XYZ_Ltd");
INSERT INTO "Documents" VALUES ("8", "103", "Contract_DEF_Inc");
INSERT INTO "Documents" VALUES ("9", "103", "Contract_GHI_LLC");
INSERT INTO "Documents" VALUES ("10", "104", "Memo_Staff_Meeting");
INSERT INTO "Documents" VALUES ("11", "105", "Newsletter_Jan_2023");
INSERT INTO "Documents" VALUES ("12", "105", "Newsletter_Feb_2023");
INSERT INTO "Documents" VALUES ("13", "105", "Newsletter_Mar_2023");
INSERT INTO "Documents" VALUES ("14", "105", "Newsletter_Apr_2023");
INSERT INTO "Documents" VALUES ("15", "105", "Newsletter_May_2023");