use serde_json::Value;
use super::Verb;
pub const GRADES: [&str; 2] = ["operator", "foot"];
pub const OFFER: Verb = Verb {
word: "offer",
params: &["workspace", "name", "grade"],
flags: &[],
summary: "offer a new device a place in this workspace: one URL, good once, for ten minutes",
detail: "The server records a pending offer for a client of that name \
and grade, and answers a one-time registration URL with the \
moment it expires. That URL is the whole of what the new device \
needs: it is printed as text and as a QR symbol, and it carries \
no key and no certificate — the device makes its own key and \
sends only the public half when it claims the URL (`lernie \
register <url>` on a lernie seat). `grade` is `operator` or \
`foot`. The server refuses a name anything was ever issued \
under; minting again under a name whose offer is still open \
replaces the code. THEN: the device shows a six-character \
confirmation word. `lernie offers <workspace>` shows the same \
word beside the offer once the device has claimed it; `lernie \
approve <workspace> <name>` seats it. Operator grade only.",
};
pub const OFFERS: Verb = Verb {
word: "offers",
params: &["workspace"],
flags: &[],
summary: "this workspace's pending offers, each with its state and confirmation word",
detail: "Every offer not yet approved or declined: its name, its grade, \
its state and when its code expires. `open` is a code nobody has \
claimed; `claimed` is a device that holds the certificate and \
has not dialled; `proved` is a device that has dialled with it, \
which a copy of the URL never could. A claimed or proved row \
carries the confirmation word — the six characters the device \
is showing. Only a proved offer can be approved.",
};
pub const APPROVE: Verb = Verb {
word: "approve",
params: &["workspace", "name"],
flags: &[],
summary: "seat a proved offer's device in this workspace",
detail: "Registers the offered client in the workspace, which is the \
moment its certificate starts to mean anything: until then the \
server refuses it everything. Refused unless the offer is \
proved. Read the word off the new device and approve the row \
that shows the same one — that comparison is the whole of what \
stops an impostor who claimed the URL first.",
};
pub const DECLINE: Verb = Verb {
word: "decline",
params: &["workspace", "name"],
flags: &[],
summary: "void an offer; one already claimed keeps its name spent",
detail: "An open offer is forgotten and its name is free again. An offer \
somebody already claimed has issued a certificate that cannot be \
recalled, so declining it keeps that certificate refused for \
good and spends the name: offer the device again under another \
one. Decline a row whose word matches nothing in front of you.",
};
pub fn offer(workspace: String, name: String, grade: String) -> Value {
OFFER.built(vec![workspace, name, grade], &[])
}
pub fn offers(workspace: String) -> Value {
OFFERS.built(vec![workspace], &[])
}
pub fn approve(workspace: String, name: String) -> Value {
APPROVE.built(vec![workspace, name], &[])
}
pub fn decline(workspace: String, name: String) -> Value {
DECLINE.built(vec![workspace, name], &[])
}