(**************************************************************************)
(*                                BELENIOS                                *)
(*                                                                        *)
(*  Copyright © 2012-2025 Inria                                           *)
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
(*  it under the terms of the GNU Affero General Public License as        *)
(*  published by the Free Software Foundation, either version 3 of the    *)
(*  License, or (at your option) any later version, with the additional   *)
(*  exemption that compiling, linking, and/or using OpenSSL is allowed.   *)
(*                                                                        *)
(*  This program is distributed in the hope that it will be useful, but   *)
(*  WITHOUT ANY WARRANTY; without even the implied warranty of            *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *)
(*  Affero General Public License for more details.                       *)
(*                                                                        *)
(*  You should have received a copy of the GNU Affero General Public      *)
(*  License along with this program.  If not, see                         *)
(*  <http://www.gnu.org/licenses/>.                                       *)
(**************************************************************************)

type uuid = string wrap <ocaml module="Belenios_core.Common_types.Uuid">
type hash = string wrap <ocaml module="Belenios_core.Common_types.Hash">
type weight = abstract wrap <ocaml module="Belenios_core.Common_types.Weight">
type recipient <ocaml predef from="Belenios_web_api.Serializable"> = abstract
type confirmation <ocaml predef from="Belenios_web_api.Serializable"> = abstract
type message_metadata <ocaml predef from="Belenios_web_api.Serializable"> = abstract

type material_message = {
  recipient : recipient;
  material : string;
  ?weight : weight option;
  ?metadata : message_metadata option;
}

type code_message = {
  lang : string;
  recipient : recipient;
  ?uuid : uuid option;
  ?state : string option;
  code : string;
}

type confirmation_message = {
  lang : string;
  uuid : uuid;
  title : string;
  contact : string option;
  confirmation : confirmation;
}

type cred_authority_info <ocaml predef from="Belenios_web_api.Serializable"> = abstract

type credentials_seed_message = {
  uuid : uuid;
  admin_id : int;
  lang : string;
  belenios_url : string;
  cred_authority_info : cred_authority_info;
  seed : string;
}

type message =
  [ Account_create of code_message
  | Account_change_password of code_message
  | Account_set_email of code_message
  | Voter_credential of material_message
  | Vote_confirmation of confirmation_message
  | Mail_login of code_message
  | Credentials_seed of credentials_seed_message
  ]

type message_payload = {
  timestamp : float;
  message : message;
  ?hmac : hash option;
}
