// 补充库标识
export const cptLibKey = 'complementaryLib';

/**
 * 判断库ID是否是补充的库ID
 * @param libID 库ID
 */
export const isCptLib = (libID: number | string): boolean => {
  return /[\da-zA-Z-]{36}/.test(String(libID));
};

/**
 * 获取补充人材机库ID，根据拥有者ID、费用定额ID拼接
 * @param ownerID 拥有者ID
 * @param compilationID 费用定额ID
 */
export const getCptLibID = (ownerID: string, compilationID: string): string => {
  return `${cptLibKey}@${ownerID}@${compilationID}`;
};

/**
 * 从补充人材机库ID中 提取 拥有者、费用定额ID
 * @param cptLibID 补充库ID
 */
export const getInfoFromCptLibID = (cptLibID: number | string): { ownerID: string; compilationID: string } => {
  const [key, ownerID, compilationID] = String(cptLibID).split('@');
  if (!key || key !== cptLibKey || !ownerID || !compilationID) {
    return { ownerID: '', compilationID: '' };
  }
  return { ownerID, compilationID };
};
