(* YOCaml a static blog generator.
   Copyright (C) 2024 The Funkyworkers and The YOCaml's developers

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   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 General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>. *)

(** Generic tools to facilitate server construction (component sharing, etc.) *)

module Kind : sig
  (** Describes if a path is a file or a directory. *)

  type t = Directory of string | File of string

  val from_path :
       is_directory:('path -> bool)
    -> concat:('path -> string -> 'path)
    -> 'path
    -> string
    -> t
  (** lift a path into a kind. *)
end

module Request_path : sig
  (** Describes the request path. *)

  type 'a t = File of 'a * string | Dir of 'a * string list | Error404

  val content_type : string -> string
  (** Give the content-type of a filename. *)

  val from_path :
       is_file:('a -> bool)
    -> is_directory:('a -> bool)
    -> concat:('a -> string -> 'a)
    -> native:('a -> string)
    -> 'a
    -> path:string
    -> 'a t
  (** [from_path] generically lift an HTTP path to a requested path. *)
end

module Pages : sig
  (** Describes the debug pages displayed. *)

  val error404 : string -> string
  val directory : string list -> Kind.t list -> string
end

(** {1 Helpers} *)

val prompt : int -> unit
(** Prompt the preamble message. *)

val exn_handler : (Format.formatter -> exn -> unit) -> exn -> unit
(** Exception handler.. *)
