package cloud.nstart.terravault.ordinis.projection;

/**
 * Конвенция ключей в Redis для projection.
 *
 * <p><b>Per-locale flat record:</b><br>
 * {@code ord:<bundle>:<dictionary>:<businessKey>:<locale>}<br>
 * Value = JSON со сплющенным data на эту локаль (готов к отдаче без processing).
 *
 * <p><b>Multi-locale raw record:</b><br>
 * {@code ord:<bundle>:<dictionary>:<businessKey>:_raw}<br>
 * Value = полный multi-locale JSON. Используется когда client запросил {@code Accept-Language: *}.
 *
 * <p><b>Index по dictionary (set):</b><br>
 * {@code ord:idx:<bundle>:<dictionary>}<br>
 * Members = businessKey'и активных записей. Для list endpoint.
 *
 * <p><b>Last seen kafka offset (для idempotency consumer'a):</b><br>
 * {@code ord:offset:<topic>:<partition>}
 */
public final class RedisKeys {

  private RedisKeys() {}

  public static String record(String bundle, String dictionary, String businessKey, String locale) {
    return "ord:" + bundle + ":" + dictionary + ":" + businessKey + ":" + locale;
  }

  public static String recordRaw(String bundle, String dictionary, String businessKey) {
    return "ord:" + bundle + ":" + dictionary + ":" + businessKey + ":_raw";
  }

  public static String dictionaryIndex(String bundle, String dictionary) {
    return "ord:idx:" + bundle + ":" + dictionary;
  }

  public static String recordKeyPattern(String bundle, String dictionary, String businessKey) {
    return "ord:" + bundle + ":" + dictionary + ":" + businessKey + ":*";
  }
}
