import gleam/json
import gleeunit
import gleeunit/should
import player
import session

pub fn main() {
  gleeunit.main()
}

pub fn serialize_player_test() {
  player.Player("CoolZero123", 55, 0)
  |> player.serialize
  |> should.equal([
    #("name", json.string("CoolZero123")),
    #("id", json.int(55)),
    #("score", json.int(0)),
  ])
}

pub fn decoder_player_test() {
  let decoder = player.decoder()
  let input_str = "{\"name\": \"CoolZero123\", \"id\": 55, \"score\": 0}"

  let assert Ok(player) = json.parse(from: input_str, using: decoder)

  should.equal(player.name, "CoolZero123")
  should.equal(player.id, 55)
  should.equal(player.score, 0)
}

pub fn serialzie_session_test() {
  session.Session(2, 55, [player.Player("CoolZero123", 55, 0)])
  |> session.serialize
  |> json.to_string
  |> should.equal(
    "{\"id\":2,\"host_user_id\":55,\"players\":[{\"name\":\"CoolZero123\",\"id\":55,\"score\":0}]}",
  )
}

pub fn desarlize_session_test() {
  let input_str =
    "{\"id\":2,\"host_user_id\":55,\"players\":[{\"name\":\"CoolZero123\",\"id\":55,\"score\":0}]}"
  let assert Ok(s) = session.deseralize(input_str)

  should.equal(s, session.Session(2, 55, [player.Player("CoolZero123", 55, 0)]))
}
