(*--------------------------------------------------------------------------- Copyright (c) 2025 Anil Madhavapeddy. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) (* Identity properties *) type property = [ | `Id | `Name | `Email | `Reply_to | `Bcc | `Text_signature | `Html_signature | `May_delete ] let property_to_string : [< property ] -> string = function | `Id -> "id" | `Name -> "name" | `Email -> "email" | `Reply_to -> "replyTo" | `Bcc -> "bcc" | `Text_signature -> "textSignature" | `Html_signature -> "htmlSignature" | `May_delete -> "mayDelete" let property_of_string s : property option = match s with | "id" -> Some `Id | "name" -> Some `Name | "email" -> Some `Email | "replyTo" -> Some `Reply_to | "bcc" -> Some `Bcc | "textSignature" -> Some `Text_signature | "htmlSignature" -> Some `Html_signature | "mayDelete" -> Some `May_delete | _ -> None (* Identity type *) type t = { id : Proto_id.t option; name : string option; email : string option; reply_to : Mail_address.t list option; bcc : Mail_address.t list option; text_signature : string option; html_signature : string option; may_delete : bool option; } let id t = t.id let name t = t.name let email t = t.email let reply_to t = t.reply_to let bcc t = t.bcc let text_signature t = t.text_signature let html_signature t = t.html_signature let may_delete t = t.may_delete let make id name email reply_to bcc text_signature html_signature may_delete = { id; name; email; reply_to; bcc; text_signature; html_signature; may_delete } let jsont = let kind = "Identity" in Jsont.Object.map ~kind make |> Jsont.Object.opt_mem "id" Proto_id.jsont ~enc:id |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name |> Jsont.Object.opt_mem "email" Jsont.string ~enc:email |> Jsont.Object.opt_mem "replyTo" (Jsont.list Mail_address.jsont) ~enc:reply_to |> Jsont.Object.opt_mem "bcc" (Jsont.list Mail_address.jsont) ~enc:bcc |> Jsont.Object.opt_mem "textSignature" Jsont.string ~enc:text_signature |> Jsont.Object.opt_mem "htmlSignature" Jsont.string ~enc:html_signature |> Jsont.Object.opt_mem "mayDelete" Jsont.bool ~enc:may_delete |> Jsont.Object.finish