import { cacheFor }     from '@/request/api/index';
import { fromFlowData } from '@/request/model';
import Router           from '@/router';

import HTTP from '../alova';


export function copyrightMethod() {
  return HTTP.Post(`/fdhb-tablet/warrantManage/getPageSets`, void 0, {
    cacheFor, name: `variate:copyright`,
    params: { k: 'copyright' },
    meta: { ignoreException: true },
    transform(data: any, headers) {
      if ( !data ) { throw { message: `无效的证书` }; }
      return [ data?.partner, data?.technicalSupporter ].filter(Boolean).join('<br>');
    },
  });
}

export function processMethod() {
  const path = unref(Router.currentRoute).path;
  return HTTP.Post<string, { tabletProcessModules?: string[]; }>(`/fdhb-tablet/warrantManage/getPageSets`, {}, {
    cacheFor, name: `variate:process`,
    params: { k: 'process', p: path },
    transform(data) {
      const options = data.tabletProcessModules ?? [];
      const ref = fromFlowData(options);
      const route = ref.get(path);
      if ( !route ) throw { message: `[路由] 配置异常无法解析正确路径，请联系管理员 (${ data?.tabletProcessModules?.join(' -> ') }})` };
      return route;
    },
  });
}

