(function() {
  const YUYAN_MODULE_GROUP = {
    id: 99901,
    title: '雨燕增强模块',
    groupName: null,
    componentKey: 'yuyan_enhanced_group_key',
    thumbnail: 'sheji',
    grayThumbnail: null,
    placeHolderImage: null,
    locationSupported: null,
    moduleRulesDO: null,
    formSchema: {},
    description: '雨燕装修大师提供的增强模块',
    groupType: null,
    subModulePrototypeList: [
      {
        id: 152720,
        title: '宽屏视频',
        groupName: '雨燕增强模块',
        componentKey: 'yuyan_widescreen_video',
        thumbnail: 'https://img.alicdn.com/tfs/TB18a.Blf2H8KJjy0FcXXaDlFXa-240-90.png?iconurl=https://img.alicdn.com/tfs/TB13dothZfpK1RjSZFOXXa6nFXa-40-40.png',
        grayThumbnail: '',
        placeHolderImage: '',
        locationSupported: 'bd',
        moduleRulesDO: {
          editable: true,
          movable: true,
          deleteable: true,
          addable: true,
          required: false,
          copyable: false,
          maxAppend: 10,
          order: 0,
          position: 0,
          renamable: false,
          supportWidthAsString: '960,1200,220',
          showable: true,
        },
        formSchema: null,
        description: '宽屏视频模块',
        groupType: null,
        subModulePrototypeList: null,
      },
      {
        id: 265120,
        title: '滚动模块',
        groupName: '雨燕增强模块',
        componentKey: 'yuyan_marquee_module',
        thumbnail: 'https://img.alicdn.com/tfs/TB1HVd2aMMPMeJjy1XcXXXpppXa-240-80.png?iconurl=https://img.alicdn.com/tfs/TB1.l3ph9zqK1RjSZFLXXcn2XXa-48-30.png',
        grayThumbnail: '',
        placeHolderImage: '',
        locationSupported: 'bd',
        moduleRulesDO: {
          editable: true,
          movable: true,
          deleteable: true,
          addable: true,
          required: false,
          copyable: false,
          maxAppend: 10,
          order: 0,
          position: 0,
          renamable: false,
          supportWidthAsString: '960,1200,220',
          showable: true,
        },
        formSchema: null,
        description: '滚动增强模块',
        groupType: null,
        subModulePrototypeList: null,
      },
      {
        id: 265013,
        title: '宽屏图片',
        groupName: '雨燕增强模块',
        componentKey: 'yuyan_image_module',
        thumbnail: 'https://img.alicdn.com/tfs/TB1PDGDuntYBeNjy1XdXXXXyVXa-240-60.png?iconurl=https://img.alicdn.com/tfs/TB1lqInhY2pK1RjSZFsXXaNlXXa-40-36.png',
        grayThumbnail: '',
        placeHolderImage: '',
        locationSupported: 'bd',
        moduleRulesDO: {
          editable: true,
          movable: true,
          deleteable: true,
          addable: true,
          required: false,
          copyable: false,
          maxAppend: 10,
          order: 0,
          position: 0,
          renamable: false,
          supportWidthAsString: '960,1200,220',
          showable: true,
        },
        formSchema: null,
        description: '宽屏图片模块',
        groupType: null,
        subModulePrototypeList: null,
      },
      {
        id: 277668,
        title: 'AI模块',
        groupName: '雨燕增强模块',
        componentKey: 'yuyan_ai_module',
        thumbnail: 'https://img.alicdn.com/tfs/TB1PDGDuntYBeNjy1XdXXXXyVXa-240-60.png?iconurl=https://img.alicdn.com/tfs/TB1lqInhY2pK1RjSZFsXXaNlXXa-40-36.png',
        grayThumbnail: '',
        placeHolderImage: '',
        locationSupported: 'bd',
        moduleRulesDO: {
          editable: true,
          movable: true,
          deleteable: true,
          addable: true,
          required: false,
          copyable: false,
          maxAppend: 10,
          order: 0,
          position: 0,
          renamable: false,
          supportWidthAsString: '960,1200,220',
          showable: true,
        },
        formSchema: null,
        description: 'AI模块',
        groupType: null,
        subModulePrototypeList: null,
      },
    ],
  };

  const _origFetch = window.fetch;
  window.fetch = async function(...args) {
    const response = await _origFetch.apply(this, args);
    const url = typeof args[0] === 'string' ? args[0] : (args[0]?.url || '');

    if (url.includes('get_prototype')) {
      try {
        const data = await response.clone().json();
        if (data?.result?.modulePrototypeDOS) {
          data.result.modulePrototypeDOS.push(YUYAN_MODULE_GROUP);
          console.log('[雨燕装修大师] get_prototype 已注入自定义模块');
          return new Response(JSON.stringify(data), {
            status: response.status,
            statusText: response.statusText,
            headers: response.headers,
          });
        }
      } catch(e) {
        console.warn('[雨燕装修大师] get_prototype 拦截失败:', e);
      }
    }

    return response;
  };
})();
