'use strict';

const CTM_PROCESS_NAME = 'Coding Task Manager';
const WALLE_PROCESS_NAME = 'Wall-E';

function normalizeInstanceTag(tag) {
  const text = String(tag || 'primary').trim();
  return text || 'primary';
}

function legacyProcessTitle(kind, tag = 'primary') {
  const normalized = normalizeInstanceTag(tag);
  return `${kind === 'walle' ? 'walle' : 'ctm'}-${normalized}`;
}

function processTitle(kind, tag = 'primary') {
  const normalized = normalizeInstanceTag(tag);
  const base = kind === 'walle' ? WALLE_PROCESS_NAME : CTM_PROCESS_NAME;
  return normalized === 'primary' ? base : `${base} ${normalized}`;
}

function processTitleCandidates(kind, tag = 'primary') {
  const current = processTitle(kind, tag);
  const legacy = legacyProcessTitle(kind, tag);
  return current === legacy ? [current] : [current, legacy];
}

module.exports = {
  CTM_PROCESS_NAME,
  WALLE_PROCESS_NAME,
  legacyProcessTitle,
  normalizeInstanceTag,
  processTitle,
  processTitleCandidates,
};
