CREATE TABLE IF NOT EXISTS api_wynacom_setting (
    Api_WynacomSettingID INT NOT NULL AUTO_INCREMENT,
    Api_WynacomSettingKey VARCHAR(100) NOT NULL,
    Api_WynacomSettingValue VARCHAR(255) NOT NULL,
    Api_WynacomSettingDescription VARCHAR(255) NULL,
    Api_WynacomSettingIsActive CHAR(1) NOT NULL DEFAULT 'Y',
    Api_WynacomSettingCreated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    Api_WynacomSettingCreatedUserID INT NOT NULL DEFAULT 0,
    Api_WynacomSettingLastUpdated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    Api_WynacomSettingLastUpdatedUserID INT NOT NULL DEFAULT 0,
    Api_WynacomSettingDeleted DATETIME NULL,
    Api_WynacomSettingDeletedUserID INT NOT NULL DEFAULT 0,
    PRIMARY KEY (Api_WynacomSettingID),
    UNIQUE KEY uq_api_wynacom_setting_key (Api_WynacomSettingKey),
    KEY idx_api_wynacom_setting_active (Api_WynacomSettingIsActive)
);

INSERT INTO api_wynacom_setting (
    Api_WynacomSettingKey,
    Api_WynacomSettingValue,
    Api_WynacomSettingDescription,
    Api_WynacomSettingIsActive,
    Api_WynacomSettingCreatedUserID,
    Api_WynacomSettingLastUpdatedUserID
) VALUES (
    'token_expired_days',
    '3',
    'Masa berlaku token Wynacom dalam hari',
    'Y',
    0,
    0
)
ON DUPLICATE KEY UPDATE
    Api_WynacomSettingValue = Api_WynacomSettingValue,
    Api_WynacomSettingDescription = VALUES(Api_WynacomSettingDescription),
    Api_WynacomSettingIsActive = 'Y',
    Api_WynacomSettingLastUpdated = NOW();
