// @requirements REQ-PRODUCT-PROCESSING-CHOICES
import {readFile} from 'node:fs/promises';
import {compileLegalDocuments,createProcessingNotice} from 'notabenda/content';
import {renderLegalLinks} from 'notabenda';
import {exampleConsentConfig} from '../static/choices-build.mjs';
export async function processingFiles(base){
const config=exampleConsentConfig(base);config.site.id='juniper-processing-choices';
const template=config.purposes[0],memory=config.purposes.find(p=>p.id==='remember-choices');
config.purposes=[{...template,id:'optional-features',name:'Optional features',description:'Run fictional optional services to demonstrate independent cookie permission and processing restrictions.',dataCategories:['Synthetic first-party sample request'],retention:'No application record is created by the sample requests.'},{...memory,dataCategories:[...memory.dataCategories,'Processing restriction activities','Pending opt-out request and policy references'],retention:'This synthetic fixture keeps local processing restrictions until browser clearing and server records until the developer resets local storage. Production retention and erasure require an operator policy.'}];
config.services=[{id:'sample-advertising',name:'Sample advertising',provider:'Juniper Notes (fictional)',location:'This local demo only',purposeIds:['optional-features'],processingActivities:['sale','sharing','targeted-advertising']},{id:'sample-tools',name:'Sample local tools',provider:'Juniper Notes (fictional)',location:'This local demo only',purposeIds:['optional-features'],processingActivities:[]},{...config.services.find(s=>s.id==='privacy-choices'),location:'Browser preference recovery and host-owned synthetic record storage',processingActivities:[]}];
config.storage=config.storage.filter(s=>s.serviceId==='privacy-choices');for(const item of config.storage)item.name=item.name.replace('juniper-choices',config.site.id);
config.storage.push({id:'processing-recovery',name:`notabenda:processing:v1:${config.site.id}:…`,serviceId:'privacy-choices',type:'localStorage',duration:'Until browser clearing; separate from retained server restrictions',classification:'necessary',necessityReason:'Preserve an explicit opt-out and retry its unconfirmed request in this fictional fixture. Review applicability and retention for a real deployment.'});
config.consent.purposes=[{id:'optional-features',scope:'sample-1'}];config.consent.services=[{id:'sample-advertising',scope:'sample-1'},{id:'sample-tools',scope:'sample-1'}];
for(const [kind,doc] of Object.entries(config.documents))doc.route=`/processing-choices/${kind}`;
const build=compileLegalDocuments(config,{mode:'preview',stylesheetUrl:'/assets/notabenda.css'});
const notice=createProcessingNotice(build.artifact,{scopeId:'privacy-choices',activities:['sale','sharing','targeted-advertising'],wording:{title:'Your privacy choices',description:'Opt out of sale, sharing and targeted advertising for this synthetic context. Cookie permission is separate and cannot remove a processing restriction.',actionLabel:'Opt out of sale, sharing and targeted advertising'}},{mode:'preview'});
return {...build.files,'processing-choices/site.json':JSON.stringify(build.publicConfig),'processing-choices/notice.json':JSON.stringify(notice),'processing-choices/sample.json':'{"fictional":true}',
'assets/processing-choices.mjs':await readFile(new URL('./client.mjs',import.meta.url),'utf8'),
'processing-choices/index.html':`
Allow optional features, then opt out above. Sample advertising stops; sample tools can continue under the same cookie permission. Reload to recover the host restriction.