export const buildPresetSignature = (form, roles) => {
  const roleEntries = Object.entries(roles || {})
    .map(([id, value]) => ({
      id: Number(id),
      monitor: Boolean(value && value.monitor),
      invite: Boolean(value && value.invite),
      confirm: Boolean(value && value.confirm)
    }))
    .sort((a, b) => a.id - b.id);
  const snapshot = {
    form: {
      warmupEnabled: Boolean(form.warmupEnabled),
      historyLimit: Number(form.historyLimit || 0),
      separateBotRoles: Boolean(form.separateBotRoles),
      requireSameBotInBoth: Boolean(form.requireSameBotInBoth),
      maxCompetitorBots: Number(form.maxCompetitorBots || 0),
      maxOurBots: Number(form.maxOurBots || 0),
      separateConfirmRoles: Boolean(form.separateConfirmRoles),
      maxConfirmBots: Number(form.maxConfirmBots || 0),
      inviteViaAdmins: Boolean(form.inviteViaAdmins),
      inviteAdminAnonymous: Boolean(form.inviteAdminAnonymous),
      inviteAdminMasterId: Number(form.inviteAdminMasterId || 0)
    },
    roles: roleEntries
  };
  return JSON.stringify(snapshot);
};
