export type Reservation={id:string;name:string;seats:number;version:number};
export type Scenario='rejected'|'conflict'|'cache';
export type SaveResult={ok:true;record:Reservation}|{ok:false;reason:string;record:Reservation};
export function saveOnServer(current:Reservation,requested:Reservation,scenario:Scenario,safe:boolean):SaveResult{
 if(scenario==='rejected')return {ok:false,reason:'The room limit is four seats. The server rejected this change.',record:{...current}};
 if(safe&&requested.version!==current.version)return {ok:false,reason:'Another editor saved a newer version. Review that record before saving again.',record:{...current}};
 return {ok:true,record:{...requested,version:current.version+1}};
}
export function reconcile(before:Reservation,optimistic:Reservation,result:SaveResult,safe:boolean){
 if(result.ok)return {editor:result.record,summary:safe?result.record:before,status:'Saved on the server.'};
 return {editor:safe?result.record:optimistic,summary:before,status:safe?result.reason:'Saved (the broken interface ignored the rejected response).'};
}
