-- Setup test data for Phase 1 validation tests  
-- Create test articles in NOM_ARTICOLE and mappings in ARTICOLE_TERTI

-- Clear any existing test mappings
DELETE FROM ARTICOLE_TERTI WHERE sku IN ('CAFE100', '8000070028685', 'TEST001');

-- Disable trigger to allow specific ID_ARTICOL values
ALTER TRIGGER trg_NOM_ARTICOLE_befoins DISABLE;

-- Create test articles in NOM_ARTICOLE with correct structure
-- Using specific ID_ARTICOL values for test consistency
INSERT INTO NOM_ARTICOLE (
    ID_ARTICOL, CODMAT, DENUMIRE, UM, 
    DEP, ID_SUBGRUPA, CANT_BAX, STERS, ID_MOD, INACTIV, 
    IN_STOC, IN_CRM, DNF, PRETACHCTVA, TAXA_RECONDITIONARE, GREUTATE,
    ID_UTIL, DATAORA
) VALUES (
    9999001, 'CAF01', 'Cafea Test - 1kg', 'BUC',
    0, 1, 1, 0, 1, 0,
    1, 1, 0, 0, 0, 1000,
    -3, SYSDATE
);

INSERT INTO NOM_ARTICOLE (
    ID_ARTICOL, CODMAT, DENUMIRE, UM,
    DEP, ID_SUBGRUPA, CANT_BAX, STERS, ID_MOD, INACTIV,
    IN_STOC, IN_CRM, DNF, PRETACHCTVA, TAXA_RECONDITIONARE, GREUTATE,
    ID_UTIL, DATAORA  
) VALUES (
    9999002, 'LAV001', 'Lavazza Gusto Forte Test', 'BUC',
    0, 1, 1, 0, 1, 0,
    1, 1, 0, 0, 0, 1000,
    -3, SYSDATE
);

INSERT INTO NOM_ARTICOLE (
    ID_ARTICOL, CODMAT, DENUMIRE, UM,
    DEP, ID_SUBGRUPA, CANT_BAX, STERS, ID_MOD, INACTIV,
    IN_STOC, IN_CRM, DNF, PRETACHCTVA, TAXA_RECONDITIONARE, GREUTATE,
    ID_UTIL, DATAORA
) VALUES (
    9999003, 'TEST001', 'Articol Test Generic', 'BUC',
    0, 1, 1, 0, 1, 0,
    1, 1, 0, 0, 0, 500,
    -3, SYSDATE
);

-- Price entry for CAF01 in default price policy (id_pol=1)
-- Used for single-component repackaging kit pricing test
MERGE INTO crm_politici_pret_art dst
USING (SELECT 1 AS id_pol, 9999001 AS id_articol FROM DUAL) src
ON (dst.id_pol = src.id_pol AND dst.id_articol = src.id_articol)
WHEN NOT MATCHED THEN INSERT (id_pol, id_articol, pret, proc_tvav)
VALUES (src.id_pol, src.id_articol, 51.50, 19);

-- Create test mappings in ARTICOLE_TERTI
-- CAFE100 -> CAF01 (repackaging: 10x1kg = 1x10kg web package)
INSERT INTO ARTICOLE_TERTI (sku, codmat, cantitate_roa, procent_pret, activ)
VALUES ('CAFE100', 'CAF01', 10, 100, 1);

-- Real GoMag SKU -> Lavazza article  
INSERT INTO ARTICOLE_TERTI (sku, codmat, cantitate_roa, procent_pret, activ)
VALUES ('8000070028685', 'LAV001', 1, 100, 1);

-- Re-enable trigger after test data creation
ALTER TRIGGER trg_NOM_ARTICOLE_befoins ENABLE;

COMMIT;

PROMPT === Test Data Setup Complete ===