(**************************************************************************)
(*                                BELENIOS                                *)
(*                                                                        *)
(*  Copyright © 2024-2024 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 datetime = string wrap <ocaml module="Datetime">
type user <ocaml predef from="Belenios_storage_api.Atd"> = abstract
type metadata <ocaml predef from="Belenios_storage_api.Atd"> = abstract
type draft_voter <ocaml predef from="Belenios_storage_api.Atd"> = abstract
type 'a template <ocaml predef from="Belenios_storage_api.Atd"> = abstract
type 'a draft_trustees <ocaml predef from="Belenios_storage_api.Atd"> = abstract

type election_dates = {
  ~creation <ocaml default="datetime_of_string {|\"2018-11-26 00:00:00.000000\"|}"> : datetime;
  ?finalization : datetime option;
  ?tally : datetime option;
  ?archive : datetime option;
  ?last_mail : datetime option;
  ?auto_open : datetime option;
  ?auto_close : datetime option;
} <ocaml field_prefix="e_">

type extended_record = {
  username : string;
  date : datetime;
  credential : string;
} <ocaml field_prefix="r_">

type 'question raw_draft_election = {
  version : int;
  owners : int list;
  group <ocaml mutable> : string;
  voters <ocaml mutable> : draft_voter list;
  questions <ocaml mutable> : 'question template;
  trustees <ocaml mutable> : abstract draft_trustees;
  metadata <ocaml mutable> : metadata;
  public_creds : string;
  public_creds_received <ocaml mutable> : bool;
  ~creation_date <ocaml default="datetime_of_string {|\"2018-11-26 00:00:00.000000\"|}">: datetime;
  ?administrator <ocaml mutable> : string option;
  ~credential_authority_visited <ocaml default="false" mutable> : bool;
  ~voter_authentication_visited <ocaml default="false" mutable> : bool;
  ~trustees_setup_step <ocaml default="1" mutable> : int;
  ~pending_credentials <ocaml default="false" mutable> : bool;
} <ocaml field_prefix="se_">

type authentication_method = [ CAS of string | Password | Unknown ]
type credential_method = [ Automatic | Manual ]
type deleted_trustee = [ Single | Pedersen of (int * int) ]

type deleted_election = {
  uuid : uuid;
  template : abstract template;
  owners : int list;
  nb_voters : int;
  nb_ballots : int;
  date : datetime;
  tallied : bool;
  authentication_method : authentication_method;
  credential_method : credential_method;
  trustees : deleted_trustee list;
  has_weights : bool;
} <ocaml field_prefix="de_">

type account = {
    id : int;
    name : string;
    ?email : string option;
    last_connected : datetime;
    authentications : user list;
    ?consent : datetime option;
    ?capabilities : int option;
    ?language : string option;
    ~default_voter_languages <ocaml default="[]"> : string list;
    ~default_contact <ocaml default="\"\""> : string;
    ?voters_limit : int option;
}
