<commit_before>package org.http4s.play

import cats.effect.Sync
import fs2.Chunk
import org.http4s.headers.`Content-Type`
import org.http4s.{
  DecodeResult,
  EntityDecoder,
  EntityEncoder,
  InvalidMessageBodyFailure,
  MediaType,
  Message,
  Uri,
  jawn
}
import org.typelevel.jawn.support.play.Parser.facade
import play.api.libs.json._

trait PlayInstances {
  def jsonOf[F[_]: Sync, A](implicit decoder: Reads[A]): EntityDecoder[F, A] =
    jsonDecoder[F].flatMapR { json =>
      decoder
        .reads(json)
        .fold(
          _ =>
            DecodeResult.failure(InvalidMessageBodyFailure(s"Could not decode JSON: $json", None)),
          DecodeResult.success(_)
        )
    }

  implicit def jsonDecoder[F[_]: Sync]: EntityDecoder[F, JsValue] =
    jawn.jawnDecoder[F, JsValue]

  def jsonEncoderOf[F[_], A](
      implicit F: EntityEncoder[F, String],
      A: Writes[A]): EntityEncoder[F, A] =
    jsonEncoder[F].contramap[A](Json.toJson(_))

  implicit def jsonEncoder[F[_]]: EntityEncoder[F, JsValue] =
    EntityEncoder[F, Chunk[Byte]]
      .contramap[JsValue] { json =>
        val bytes = json.toString.getBytes("UTF8")
        Chunk.bytes(bytes)
      }
      .withContentType(`Content-Type`(MediaType.application.json))

  implicit val writesUri: Writes[Uri] =
    Writes.contravariantfunctorWrites.contramap[String, Uri](implicitly[Writes[String]], _.toString)

  implicit val readsUri: Reads[Uri] =
    implicitly[Reads[String]].flatMap { str =>
      Uri
        .fromString(str)
        .fold(
          _ =>
            new Reads[Uri] {
              def reads(json: JsValue): JsResult[Uri] = JsError("Invalid uri")
            },<commit_msg>Undo play-json change to avoid (legitimate) unused parameter warning<commit_after>package org.http4s.play

import cats.effect.Sync
import fs2.Chunk
import org.http4s.headers.`Content-Type`
import org.http4s.{
  DecodeResult,
  EntityDecoder,
  EntityEncoder,
  InvalidMessageBodyFailure,
  MediaType,
  Message,
  Uri,
  jawn
}
import org.typelevel.jawn.support.play.Parser.facade
import play.api.libs.json._

trait PlayInstances {
  def jsonOf[F[_]: Sync, A](implicit decoder: Reads[A]): EntityDecoder[F, A] =
    jsonDecoder[F].flatMapR { json =>
      decoder
        .reads(json)
        .fold(
          _ =>
            DecodeResult.failure(InvalidMessageBodyFailure(s"Could not decode JSON: $json", None)),
          DecodeResult.success(_)
        )
    }

  implicit def jsonDecoder[F[_]: Sync]: EntityDecoder[F, JsValue] =
    jawn.jawnDecoder[F, JsValue]

  def jsonEncoderOf[F[_]: EntityEncoder[?[_], String], A: Writes]: EntityEncoder[F, A] =
    jsonEncoder[F].contramap[A](Json.toJson(_))

  implicit def jsonEncoder[F[_]]: EntityEncoder[F, JsValue] =
    EntityEncoder[F, Chunk[Byte]]
      .contramap[JsValue] { json =>
        val bytes = json.toString.getBytes("UTF8")
        Chunk.bytes(bytes)
      }
      .withContentType(`Content-Type`(MediaType.application.json))

  implicit val writesUri: Writes[Uri] =
    Writes.contravariantfunctorWrites.contramap[String, Uri](implicitly[Writes[String]], _.toString)

  implicit val readsUri: Reads[Uri] =
    implicitly[Reads[String]].flatMap { str =>
      Uri
        .fromString(str)
        .fold(
          _ =>
            new Reads[Uri] {
              def reads(json: JsValue): JsResult[Uri] = JsError("Invalid uri")
            },
{'fraction_non_alphanumeric': 0.12917528820573457, 'fraction_numerical': 0.0029559562518474726, 'mean_word_length': 3.1521472392638037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6959094', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1121, 'n_words': 209}