@namespace("keybase.1")

protocol rekey {
  import idl "common.avdl";

  record TLF {
    TLFID id;
    string name;
    array<string> writers;
    array<string> readers;
    boolean isPrivate;
  }

  record ProblemTLF {
    TLF tlf;
    int score;

    // MK Note 2016.06.29 -- Please excuse snake case here. It's too much
    // of a pain to change it on the server, so leave it here.
    @lint("ignore")
    array<KID> solution_kids;
  }

  /**
   ProblemSet is for a particular (user,kid) that initiated a rekey problem.
   This problem consists of one or more problem TLFs, which are individually scored
   and have attendant solutions --- devices that if they came online can rekey and
   solve the ProblemTLF.
   */
  record ProblemSet {
    User user;
    KID kid;
    array<ProblemTLF> tlfs;
  }

  record ProblemSetDevices {
    ProblemSet problemSet;
    array<Device> devices;
  }

  enum Outcome {
    NONE_0,
    FIXED_1,
    IGNORED_2
  }

  record RevokeWarning {
    array<TLF> endangeredTLFs;
  }

  /**
   ShowPendingRekeyStatus shows either pending gregor-initiated rekey harassments
   or nothing if none were pending.
   */
  void showPendingRekeyStatus(int sessionID);

  /**
   GetPendingRekeyStatus returns the pending ProblemSetDevices.
   */
  ProblemSetDevices getPendingRekeyStatus(int sessionID);

  /**
   DebugShowRekeyStatus is used by the CLI to kick off a "ShowRekeyStatus" window for
   the current user.
   */
  void debugShowRekeyStatus(int sessionID);

  /**
   RekeyStatusFinish is called when work is completed on a given RekeyStatus window. The Outcome
   can be Fixed or Ignored.
   */
  Outcome rekeyStatusFinish(int sessionID);

  /**
   RekeySync flushes the current rekey loop and gets to a good stopping point
   to assert state. Good for race-free testing, not very useful in production.
   Force overrides a long-snooze.
   */
  void rekeySync(int sessionID, boolean force);

  /**
   GetRevokeWarning computes the TLFs that will be endangered if actingDevice
   revokes targetDevice.
   */
  RevokeWarning getRevokeWarning(int session, DeviceID actingDevice, DeviceID targetDevice);
}
