export function convertBucketToFormValues(item) {
  if (!item) {
    return {
      indexPagePath: 'index.html',
      errorPagePath: 'index.html',
      responseHeaders: [
        { name: 'Cache-Control', value: 'no-cache' }
      ]
    };
  }
  return {
    domain: item.domain,
    indexPagePath: item.indexPagePath,
    errorPagePath: item.errorPagePath,
    isCacheEnabled: item.isCacheEnabled,
    versionIdentifier: item.versionIdentifier,
    responseHeaders: Object.entries(item.responseHeaders || {}).map(([name, value]) => ({ name, value }))
  };
}
export function convertFormValuesToBucket(values) {
  // simple folders don't have the website host related fields
  if (values.type === 'simple-folder') {
    return {
      domain: values.domain,
      indexPagePath: '',
      errorPagePath: '',
      isCacheEnabled: false,
      versionIdentifier: 'path',
      region: 'eu-central-1'
    };
  }
  const responseHeaders = {};
  (values.responseHeaders || []).forEach(({ name, value }) => {
    responseHeaders[name] = value;
  });
  return {
    domain: values.domain,
    indexPagePath: values.indexPagePath,
    errorPagePath: values.errorPagePath,
    isCacheEnabled: true,
    versionIdentifier: 'header',
    responseHeaders,
    region: 'eu-central-1'
  };
}
