-- ============================================================
-- BCV Exchange Rate Process Registration for iDempiere v10
-- ============================================================

-- 1. Register the Process
INSERT INTO AD_Process (
    AD_Process_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, Value, Description, Help, ClassName, IsReport, IsDirectPrint,
    IsServerProcess, IsBetaFunctionality, AccessLevel
) VALUES (
    50001, 0, 0, 'Y', CURRENT_TIMESTAMP, 0, CURRENT_TIMESTAMP, 0,
    'BCV Exchange Rate Update',
    'BCVExchangeRate',
    'Fetches USD/VES exchange rate from BCV official API and registers it',
    'Connects to BCV API to get the latest USD/VES exchange rate.',
    'com.venezuela.bcvrate.process.BCVExchangeRateProcess',
    'N', 'N', 'Y', 'N', '3'
);

-- 2. Register Process Parameters

INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, Description, AD_Process_ID, AD_Reference_ID, AD_Val_Rule_ID,
    IsMandatory, IsRange, FieldLength, DefaultValue, SeqNo,
    IsEncrypted, IsCentrallyMaintained, EntityType
) VALUES (
    50001, 0, 0, 'Y', CURRENT_TIMESTAMP, 0, CURRENT_TIMESTAMP, 0,
    'Client', 'Client for this installation',
    50001, 18, 100,
    'Y', 'N', 0, '@#AD_Client_ID@', 10,
    'N', 'Y', 'D'
);

INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, Description, AD_Process_ID, AD_Reference_ID, AD_Val_Rule_ID,
    IsMandatory, IsRange, FieldLength, DefaultValue, SeqNo,
    IsEncrypted, IsCentrallyMaintained, EntityType
) VALUES (
    50002, 0, 0, 'Y', CURRENT_TIMESTAMP, 0, CURRENT_TIMESTAMP, 0,
    'Conversion Type', 'Currency conversion type',
    50001, 18, 153,
    'Y', 'N', 0, 'S', 20,
    'N', 'Y', 'D'
);

INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, Description, AD_Process_ID, AD_Reference_ID,
    IsMandatory, IsRange, FieldLength, DefaultValue, SeqNo,
    IsEncrypted, IsCentrallyMaintained, EntityType
) VALUES (
    50003, 0, 0, 'Y', CURRENT_TIMESTAMP, 0, CURRENT_TIMESTAMP, 0,
    'Date From', 'Start date for rate lookup',
    50001, 16,
    'N', 'N', 0, '@#Date@', 30,
    'N', 'Y', 'D'
);

INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, Description, AD_Process_ID, AD_Reference_ID,
    IsMandatory, IsRange, FieldLength, DefaultValue, SeqNo,
    IsEncrypted, IsCentrallyMaintained, EntityType
) VALUES (
    50004, 0, 0, 'Y', CURRENT_TIMESTAMP, 0, CURRENT_TIMESTAMP, 0,
    'Date To', 'End date for rate lookup',
    50001, 16,
    'N', 'N', 0, '@#Date@', 40,
    'N', 'Y', 'D'
);

INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, Description, AD_Process_ID, AD_Reference_ID,
    IsMandatory, IsRange, FieldLength, DefaultValue, SeqNo,
    IsEncrypted, IsCentrallyMaintained, EntityType
) VALUES (
    50005, 0, 0, 'Y', CURRENT_TIMESTAMP, 0, CURRENT_TIMESTAMP, 0,
    'Simulation Mode', 'Run in simulation mode - no actual changes saved',
    50001, 28,
    'N', 'N', 0, 'N', 50,
    'N', 'Y', 'D'
);

-- 3. Verify
SELECT p.Name, p.ClassName, 
    (SELECT COUNT(*) FROM AD_Process_Para pp WHERE pp.AD_Process_ID = p.AD_Process_ID) as Params
FROM AD_Process p WHERE p.ClassName = 'com.venezuela.bcvrate.process.BCVExchangeRateProcess';
