-- SQL statements to register the W-TOST rule in the QCS database
-- This file should be executed against both qcs.db files in quality-check-software and qcs-admin projects
-- Consistency check between staging system ToS and Stage

-- Step 1: Add validation message for W-TOST
INSERT INTO validationMessage(id,code,type,reference,description) VALUES 
('213','W-TOST','WARNING','','W-TOST: Staging system is not defined.');

-- Step 2: Add rule definition for W-TOST
INSERT INTO ruledefinition(ID,NAME,DESCRIPTION,POSITIVE,CASESENSITIVITY,LOCATION,IMPLEMENTATION,VALIDATIONMESSAGE_ID,RULETYPE_ID) VALUES 
(317,'Staging System Missing','Staging system is not defined',true,'INSENSITIVE','eu.europa.ec.jrc.qcs.engine.rule.crossfield.encr2020','StagingSystemMissingRule',213,8);

-- Step 3: Add rule to ENCR 2020 protocol (protocol_id=11) with priority 7 (cross-field rules level)
INSERT INTO protocolToRule(id,protocol_id,priority,block,ruleDefinition_id) VALUES 
(371,11,7,0,317);

-- Step 4: Rule-to-Field Mappings (2 fields)
INSERT INTO ruletofield(id,protocol_id,ruledefinition_id,target_id,position,key,field_id) VALUES
(1645,11,317,3,1,0,98),  -- ToS - Staging system (field_id=98 - INCIDENCE_STAGE_SYSTEM)
(1646,11,317,3,2,0,99);  -- Stage (field_id=99 - INCIDENCE_STAGE)
