defmodule FishjamWeb.ApiSpec.Room do
  require OpenApiSpex

  alias FishjamWeb.ApiSpec.{Component, Peer}
  alias OpenApiSpex.Schema

  defmodule Config do
    @moduledoc false

    require OpenApiSpex

    OpenApiSpex.schema(%{
      title: "RoomConfig",
      description: "Room configuration",
      type: :object,
      properties: %{
        roomId: %Schema{
          type: :string,
          description:
            "Custom id used for identifying room within Fishjam. Must be unique across all rooms. If not provided, random UUID is generated.",
          nullable: true
        },
        maxPeers: %Schema{
          type: :integer,
          minimum: 1,
          example: 10,
          description: "Maximum amount of peers allowed into the room",
          nullable: true
        },
        videoCodec: %Schema{
          description: "Enforces video codec for each peer in the room",
          type: :string,
          enum: ["h264", "vp8"],
          nullable: true
        },
        webhookUrl: %Schema{
          description: "URL where Fishjam notifications will be sent",
          type: :string,
          example: "https://backend.address.com/fishjam-notifications-endpoint",
          nullable: true
        },
        peerlessPurgeTimeout: %Schema{
          description:
            "Duration (in seconds) after which the room will be removed if no peers are connected. If not provided, this feature is disabled.",
          type: :integer,
          minimum: 1,
          example: 60,
          nullable: true
        },
        peerDisconnectedTimeout: %Schema{
          description:
            "Duration (in seconds) after which the peer will be removed if it is disconnected. If not provided, this feature is disabled.",
          type: :integer,
          minimum: 1,
          example: 60,
          nullable: true
        }
      }
    })
  end

  OpenApiSpex.schema(%{
    title: "Room",
    description: "Description of the room state",
    type: :object,
    properties: %{
      id: %Schema{description: "Room ID", type: :string, example: "room-1"},
      config: Config,
      components: %Schema{
        type: :array,
        items: Component,
        description: "List of all components"
      },
      peers: %Schema{
        type: :array,
        items: Peer,
        description: "List of all peers"
      }
    },
    required: [:id, :config, :components, :peers]
  })
end
