setInterval(() => {

}, 15000);
const ProcessManager = require('./ProcessManager');
const helper = require('./src/helper');
const HttpClient = require('./src/HttpClient');
const redis_help = require('./src/use_redis'); 
const tools = require('./tools');
const config = require('./etc/config.json')
const hy_search_book = require('./src/api/hy/hy_search_book'); 

const axios = require('axios');
function getPlatformInfoByI(PlatformConfig,tg_platform_id){
    for (let index = 0; index < PlatformConfig.length; index++) {
        const element = PlatformConfig[index];
        if(element.tg_platform_id==tg_platform_id){
            return element
        }
    }
    return null
}

function getMainInfoById(MainConfig,main_id){
    // console.log("MainConfig:",MainConfig)
    for (let index = 0; index < MainConfig.length; index++) {
        const element = MainConfig[index];
        if(element.id==main_id){
            return element
        }
    }
    return null
}
let isInit = false
// config.isDebug
if(config.isDebug){
    redis_help.connect( async (results)=>{
        if(results){
            if(isInit){
                return
            }
            isInit = true
            // let yw_login = await require('./src/api/yw/yw_login').get_captcha()
            // let zh_book_data = await require('./src/api/zh/zh_search_book').search_id("1864355654438887424")
            // console.log("zh_book_data:",zh_book_data)
            // await redis_help.setKeyValue("OPENSESSID","9077ffcc5ca974e2c0e78502a24c9053")
            // await require('./src/api/yw/get_book_tg_chapter_id').get_book_tg_chapter_id("20879682908817006")
            // await redis_help.setKeyValue("OPENSESSID","ada39ae2c1286d1be3bd32e300951fff")

            // await require('./src/api/yw/getActiveInfo').getActiveInfo()

            // let MainConfig = await redis_help.getKeyValue("MainConfig")
            // MainConfig = JSON.parse(MainConfig)
            // let PlatformConfig = await redis_help.getKeyValue("PlatformConfig")
            // PlatformConfig = JSON.parse(PlatformConfig)

            // let PlatformInfo =  getPlatformInfoByI(PlatformConfig,config.platform_yuewen)

            // let main_info = getMainInfoById(MainConfig,178) //180

            // let data = {
            //     product_id:"27524924504527406",
            //     product_name:"为爱冲锋的勇士"
            // }
            // // console.log("PlatformInfo:",PlatformInfo)
            // // console.log("main_info:",main_info)
            // await require("./5_CREATE_LINK_FACTORY/yw_create_link").runTask(data,main_info,PlatformInfo,()=>{

            // })


            
            // let {promotion_name} = await require("./5_CREATE_LINK_FACTORY/qm_create_link").runTask(data,main_info,PlatformInfo,()=>{

            // })
            // console.log("promotion_name:",promotion_name)

            // let res = await require('./src/api/dz/dz_new_search_book').search_id("11010292075")
            // console.log("res:",res)
                // let response =  helper.resolveDomain("sdksaleapi.hubeidehuic.com")
                // console.log("response:",response)
            // try {
            //     const response = await makeRequest('PHWYF50CPI3');
            //     console.log("response:",response)
          
            // } catch (error) {
            //     console.error('Error in main execution:', error);
            // }

            // main()
            // let hy_book_data = await require('./2_PRODUCT_FACTORY/collect_hy_book').runTask({book_id:"1869900926728654850"})
            // console.log("hy_book_data:",hy_book_data)
        }
    })
}




// async function makeRequest(key = '') {
//     const url = `https://sdksaleapi.hubeidehuic.com/open_sdk/reader/directory/list/v1?novelsale_aid=40017686&novelsdk_aid=638505&novelsdk_version_code=230&novelsdk_device_type=V2049A&promotion_code=${key}&novelsdk_device_platform=android&version_code=290400&device_type=V2049A&sale_app_id=40017686&book_id&force_no_user_id=true&novelsdk_app_name=undefined&app_name=aweme&device_brand=vivo&device_platform=android&aid=1128&mini_app_version=2.3.0&iid=2936130190182979&device_id=825067091580075&ac=wifi&channel=douyin-huidu-gw-huidu-2940&version_name=29.4.0&os=android&ssmix=a&language=zh&os_api=31&os_version=12&manifest_version_code=290400&resolution=1080*2193&dpi=480&update_version_code=29400100&_rticket=1735289341306&first_launch_timestamp=1733382087&last_deeplink_update_version_code=0&cpu_support64=true&host_abi=arm64-v8a&is_guest_mode=0&app_type=normal&minor_status=0&appTheme=light&is_preinstall=0&need_personal_recommend=1&is_android_pad=0&is_android_fold=0&ts=1735289340&cdid=623fd2d5-5680-4aa4-95e8-78378a2ac7c5`;

//     const headers = {
//         'Connection': 'keep-alive',
//         'Cookie': 'sid_tt=85486acb04e1918afbee91a9466a9fdc;ssid_ucp_v1=1.0.0-KDVhZTIzM2QyOGFlMGE1MWRhMGIzNmI1MzFmZjlmMTVlODhjYmJiOTkKFQjr19Cz7syDAxC9zrm7Bhip_CY4CBoCbGYiIDg1NDg2YWNiMDRlMTkxOGFmYmVlOTFhOTQ2NmE5ZmRj;is_staff_user=false;sid_ucp_v1=1.0.0-KDVhZTIzM2QyOGFlMGE1MWRhMGIzNmI1MzFmZjlmMTVlODhjYmJiOTkKFQjr19Cz7syDAxC9zrm7Bhip_CY4CBoCbGYiIDg1NDg2YWNiMDRlMTkxOGFmYmVlOTFhOTQ2NmE5ZmRj;sessionid=85486acb04e1918afbee91a9466a9fdc;sessionid_ss=85486acb04e1918afbee91a9466a9fdc;uid_tt=88e8f06afa51aef4fac18f5d77607921;sid_guard=85486acb04e1918afbee91a9466a9fdc%7C1735288637%7C5184000%7CTue%2C+25-Feb-2025+08%3A37%3A17+GMT;passport_csrf_token=08c2b9062233b43ce0e2dd24171203b1;odin_tt=9783bbcf8f09663820810574a01f08b307b6e74c90aa3d8a3b4a80faa9a7d4b197d7e807043c111dcbabde8551e1111145cc87c65fce067f3c532bd796b3681a;uid_tt_ss=88e8f06afa51aef4fac18f5d77607921;passport_csrf_token_default=08c2b9062233b43ce0e2dd24171203b1;store-region=cn-gd;store-region-src=uid;n_mh=9-mIeuD4wZnlYrrOvfzG3MuT6aQmCUtmr8FxV8Kl8xY',
//         'User-Agent': 'Mozilla/5.0 (Linux; Android 12; V2049A Build/SP1A.210812.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/120.0.6099.193 Mobile Safari/537.36 aweme/29.4.0 ToutiaoMicroApp/3.21.0 PluginVersion/29409006',
//         'bdp-sec-uid': 'MS4wLjABAAAA1M_29BGiEjsgNHMP-bmblk-9qGkx5vN7Y3HgltXiFghmy1mfPlH3eonnTWpXANjE',
//         'bdp-did': '825067091580075',
//         'bdp-channel': 'douyin-huidu-gw-huidu-2940',
//         'bdp-device-timezone-offset': '28800',
//         'bdp-os-version': '12',
//         'bdp-os-name': 'Android',
//         'bdp-uid': '1788263942327546',
//         'bdp-version-code': '290400',
//         'bdp-device-platform': 'Android',
//         'bdp-aid': '1128',
//         'bdp-device-manufacturer': 'vivo',
//         'bdp-app-id': 'tt26e45059b9d1239401',
//         'bdp-device-model': 'V2049A',
//         'Content-Type': 'application/json',
//         'activity_now_client': '0',
//         'x-bd-kmsv': '1',
//         'x-tt-request-tag': 's=-1;p=1',
//         'x-tt-trace-id': '00-074e072b0d2ee64e6e8d4abbf55d0468-074e072b0d2ee64e-01',
//         'X-Argus': '/WluZw==',
//         'X-Gorgon': '8404f06a00014b0d761b864b2932a41f362b9276f3488e7700de',
//         'X-Helios': 'AkKvNQvLH57rNKMEdZDNQPlc89Q1Zrs974uhRy+IDcTR/y8Z',
//         'X-Khronos': '1735289341',
//         'X-Ladon': 'Z25p/Q==',
//         'X-Medusa': '/mluZwqBMZ0qvrJcK0OmF6qmD3/QqgABDTUpyT1IA9+MOFfCQlYXoNnb+C/rkhLwH0AzGIam8DGpfzu3MFDs3fD3Jx12yo1AKxmV8ar5cQEJ+yz2srKfjMWVZhnlSHsA8UOdYdeclol6hoyOKCcvD9k+84icb0lW39sUS4b+3c/ZdQ2g/VnINn0Bpn+V99xK211ut9hvj+pP6zAVmrqx+c86fuUyOPwBgmLtJdoya9Z5ChWFBUpxgDZiurbYqGWHG1vDjIJSnKdKLRBhRNCmsvXf7lPifdINI8I3UOlRrZJW4m/sbQ46JlozT8Dza62mFCUJaMXSVXxrPdVxq9C06cZiwamtMQw6cnQZxcI0B2R2i65Ct45ohgrJE2g4z+nZRVrpBO9ApgIXQ/sp6jPKfbkSXHFzykdk75Ktwz67Vji7puQOOUUlyeMkaBGvEaq9EZnwOyJ3VxggUaqaH5CtKfYD7lnAM4TbjtLE3SMfZZNviajoNh7ouLeyNLUab/Qd9+MBMbWsTN49BwVlOUHKn9hp56XqRNWIWyrA55jDqL6iicuXtb8Xx//kvkccyUByLEde72oGf2/IRBIAgCvfVXH/hP6wJy1f6XjL0Or6I1qX98gWSGvN9HYObpKNGm/64vtoSpHDC1JWtcuf5ZzlsA4R8XbZKS/Tn0Y9kC89pmPnHYLscWtOFoirIRJ0DXqF/PM3kB4jilEe5Y26cvQK2LaSYcuKX7iL4rWLlVrWIh7EkoFH9Un4f8hruVSbhJMWbN+dXZyNn5BHq/+rASd0pCts3fz05xX4dYlfawDeX74MhFxnKcPZu9pS2hjqDZAPmuqKo/DWWDcsO2wT0R0Fd5k/rwtXFOxQgH07cDVkeIDpLjlT3jBdxQ6X9eDfC/EP+nQv+9WgwKkeG5FXDiIbd1++iS6Mb9V4OHmUowZDopiRFqCD5GeBQTkwEe8w05QJ4Dhdu5a5l1y3CzpS/hGgwr9Sos0QrrVXJI7x6Ah1+U05c4TNHXRe8lBUPJNWUHWBXgKznDKBh1+O+Y+jqKxTyIldTfkfXP/5H13/3Hk='
//     };

//     try {
//         const response = await axios({
//             method: 'get',
//             url: url,
//             headers: headers,
//             httpsAgent: new (require('https').Agent)({
//                 rejectUnauthorized: false
//             })
//         });
        
//         console.log(response.data);
//         return response.data;
//     } catch (error) {
//         console.error('Error:', error.message);
//         throw error;
//     }
// }

// let data = await hy_search_book.search_id("1868479666362478594")
// console.log("data:",data)

        //  let response =  helper.resolveDomain("clipvideoup.s6kuwan.com")
        //  console.log("response:",response)



            // let MainConfig = await redis_help.getKeyValue("MainConfig")
            // MainConfig = JSON.parse(MainConfig)
            // let PlatformConfig = await redis_help.getKeyValue("PlatformConfig")
            // PlatformConfig = JSON.parse(PlatformConfig)

            // let PlatformInfo =  getPlatformInfoByI(PlatformConfig,4)

            // let main_info = getMainInfoById(MainConfig,150)

            // let data = {
            //     product_id:"11010288676",
            //     product_name:"侍女有谋"
            // }
 
            // require("./5_CREATE_LINK_FACTORY/dz_create_link").runTask(data,main_info,PlatformInfo,()=>{

            // })

            // let data = await require('./src/api/dz/dz_search_book').search_id('11010288676')
            // console.log("data:",data)
            //  require('./src/api/qm/qm_search_book').search_id('396740')
            // console.log("results:",await redis_help.getKeyValue("isPauseTask"))




            // let MainConfig = await redis_help.getKeyValue("MainConfig")
            // MainConfig = JSON.parse(MainConfig)
            // let PlatformConfig = await redis_help.getKeyValue("PlatformConfig")
            // PlatformConfig = JSON.parse(PlatformConfig)

            // let PlatformInfo =  getPlatformInfoByI(PlatformConfig,3)

            // let main_info = getMainInfoById(MainConfig,151)

            // let data = {
            //     product_id:"393425",
            //     product_name:"转学生自称苗疆圣子，可我才是真圣子"
            // }
 
            // let {promotion_name} = await require("./5_CREATE_LINK_FACTORY/qm_create_link").runTask(data,main_info,PlatformInfo,()=>{

            // })
            // console.log("promotion_name:",promotion_name)
            // let n_data = await require("./src/api/qm/get_qm_promotion").getPromotionList(promotion_name)
            // console.log("get_qm_promotion:",n_data)


// let get_hy_group_mapping = require('./src/api/hy/get_hy_group_mapping');
// get_hy_group_mapping.get_group_mapping((data)=>{
//     if(data.code==200){
//         let list = data.data
//     }
//     console.log("get_hy_group_mapping:",data)
// })

// setTimeout( async ()=>{
//     let black_books = await redis_help.getKeyValue("all_black_books")
//     console.log("black_books:",black_books)
// },5000)
// let main = async function(){
//     let test = new HttpClient()
//     const postData = {
//         cmd:"create_link",
//         name:"台风夜老婆去救男秘书",
//         bookId:"1848991033902665730",
//         topUpTemplateId:"1854833762266247169",
//         passBackTemplateId:"6",
//         paidPoint:"9999999",
//         token:await tools.getHyToken()
//     };

//     let data = {
//         "name": postData.name,
//         "bookId": postData.bookId,
//         "passBackTemplateId":  postData.passBackTemplateId,
//         "adPassbackTemplateId": "",
//         "topUpTemplateId": postData.topUpTemplateId,
//         "mediaChannel": "1",
//         "group": "35", 
//         "paidPoint": postData.paidPoint,
//         "site": "5" 
//     }
//     let res =  await test.otherPost( helper.getHyCreateLinkOpt(postData.token) ,data)
//     console.log("res:",res)

//     let response = {
//         "message": "create_link successfully",
//         "received_data":{"originalId":res["data"]["originalId"],
//                          "appId":res["data"]["appId"],
//                          "launchPath":res["data"]["launchPath"],
//                          "fullPath":res["data"]["fullPath"],
//                          "wxMountLink":res["data"]["wxMountLink"]}
//     }
//     console.log("response:",response)
// }


// var main = function(){
//     require("./2_PRODUCT_FACTORY/PRODUCT_FACTORY")
//     require("./5_CREATE_LINK_FACTORY/CREATE_LINK_FACTORY")
//     require("./MAIN_SERVE_FACTORY/MAIN_SERVE_FACTORY")
//     require("./0_RECEIVE_FACTORY/RECEIVE_FACTORY")
//     require("./1_FILTER_FACTORY/FILTER_FACTORY")
// }


// let main = function(){
//     let manager = new ProcessManager()
//     manager.start()
//     manager.workers.forEach((v,k)=>{
//         if (v.process) {
//             v.process.send({ 
//                 type: 'config', 
//                 data: { /* 配置数据 */ } 
//             });
//         }
//     })
// }

