import { Attribute, Predicate } from '@hyperledger/aries-oca/build/legacy';
export const buildFieldsFromAnonCredsCredential = credential => {
  var _credential$credentia;
  return (credential === null || credential === void 0 || (_credential$credentia = credential.credentialAttributes) === null || _credential$credentia === void 0 ? void 0 : _credential$credentia.map(attr => new Attribute(attr))) || [];
};
export const buildFieldsFromW3cCredsCredential = value => {
  return Object.entries(value.attributes).filter(([key]) => key !== 'id').map(([key, value]) => {
    let formattedValue;
    if (typeof value === 'object' && value !== null) {
      formattedValue = JSON.stringify(value); // Convert object to string
    } else {
      formattedValue = value;
    }
    return new Attribute({
      name: key,
      value: formattedValue,
      mimeType: typeof value === 'number' ? 'text/number' : 'text/plain'
    });
  }) || [];
};
export const buildFieldsFromAnonCredsProofRequestTemplate = data => {
  const fields = [];
  if (data.requestedAttributes) {
    for (const item of data.requestedAttributes) {
      if (item.name) {
        fields.push(new Attribute({
          name: item.name,
          value: null,
          ...item
        }));
      }
      if (item.names) {
        for (const name of item.names) {
          fields.push(new Attribute({
            name,
            value: null,
            ...item
          }));
        }
      }
    }
  }
  if (data.requestedPredicates) {
    for (const item of data.requestedPredicates) {
      fields.push(new Predicate({
        pType: item.predicateType,
        pValue: item.predicateValue,
        ...item
      }));
    }
  }
  return fields;
};
export const buildFieldsFromSharedAnonCredsProof = data => {
  const fields = [];
  for (const attribute of data.sharedAttributes) {
    fields.push(new Attribute({
      name: attribute.name,
      value: attribute.value
    }));
  }
  for (const attributesGroup of data.sharedAttributeGroups) {
    for (const attribute of attributesGroup.attributes) {
      fields.push(new Attribute({
        name: attribute.name,
        value: attribute.value
      }));
    }
  }
  for (const predicate of data.resolvedPredicates) {
    fields.push(new Predicate({
      name: predicate.name,
      pType: predicate.predicateType,
      pValue: predicate.predicateValue,
      satisfied: true
    }));
  }
  return fields;
};
export const buildOverlayFromW3cCredential = async ({
  credentialDisplay,
  language,
  resolver
}) => {
  const params = {
    identifiers: {
      schemaId: '',
      credentialDefinitionId: credentialDisplay.id
    },
    meta: {
      alias: credentialDisplay.display.issuer.name,
      credConnectionId: undefined,
      credName: credentialDisplay.display.name
    },
    attributes: buildFieldsFromW3cCredsCredential(credentialDisplay),
    language
  };
  const bundle = await resolver.resolveAllBundles(params);
  return {
    ...bundle,
    presentationFields: buildFieldsFromW3cCredsCredential(credentialDisplay)
  };
};
//# sourceMappingURL=oca.js.map