import mode
import gleam/io
import gleam/list
import definition
import gleam/json
import gleam/int
import parser
pub fn main() -> Nil {
  let input = "ljiosfgdjiosdfgj
  @2! A slightly important statement !1 I believe is wrong, !- quoted inside another quote.
  !3 A slightly important statement I believe is wrong, quoted inside another quote.
  #3!2@2 A slightly important statement I believe is wrong, quoted inside another quote.

  !2@3 important trusted but @- important !5 more important !- 2 important and !- normal"
  io.print(line_to_json(parser.handler(input)))
  Nil
}

fn inline_to_json(inline: definition.Inline) -> json.Json {
  case inline {
    definition.Text(text) ->
      json.object([
        #("type", json.string("text")),
        #("value", json.string(text)),
      ])

    definition.Push(feeling) ->
      case feeling {
        definition.Marking(level) ->
          json.object([
            #("type", json.string("marking")),
            #("value", json.int(level)),
          ])

        definition.Hirachy(level) ->
          json.object([
            #("type", json.string("hirachy")),
            #("value", json.int(level)),
          ])

        definition.Truth(level) ->
          json.object([
            #("type", json.string("truth")),
            #("value", json.int(level)),
          ])

        definition.Quote(level) ->
          json.object([
            #("type", json.string("quote")),
            #("value", json.int(level)),
          ])
      }

    definition.Pop(text) ->
      json.object([
        #("type", json.string("pop")),
        #("value",   case text {
          mode.Hirachy -> json.string("Hirachy")
          mode.Truth -> json.string("Truth")
          mode.Marking -> json.string("Marking")
          mode.Quote -> json.string("Quote")
        }
),
      ])
  }
}

fn line_to_json(line: definition.Line) -> String {
  let definition.Line(inlines) = line

  json.array(inlines, inline_to_json)
  |> json.to_string}
pub fn testing(input: String) -> String {
  line_to_json(parser.handler(input))
}
