# `Ltix.GradeService.LineItem`
[🔗](https://github.com/DecoyLex/ltix/blob/main/lib/ltix/grade_service/line_item.ex#L1)

A line item (gradebook column) in the platform's gradebook.

Line items hold results for a specific activity and set of users.
Each has a label, maximum score, and optional bindings to resource
links or tool resources.

## Examples

    {:ok, item} = Ltix.GradeService.LineItem.from_json(%{
      "id" => "https://lms.example.com/lineitems/1",
      "label" => "Chapter 5 Test",
      "scoreMaximum" => 60,
      "tag" => "grade"
    })

    item.label
    #=> "Chapter 5 Test"

    item.score_maximum
    #=> 60

# `t`

```elixir
@type t() :: %Ltix.GradeService.LineItem{
  end_date_time: DateTime.t() | nil,
  extensions: %{optional(String.t()) =&gt; term()} | nil,
  grades_released: boolean() | nil,
  id: String.t() | nil,
  label: String.t() | nil,
  resource_id: String.t() | nil,
  resource_link_id: String.t() | nil,
  score_maximum: number() | nil,
  start_date_time: DateTime.t() | nil,
  tag: String.t() | nil
}
```

# `from_json`

```elixir
@spec from_json(map()) :: {:ok, t()} | {:error, Exception.t()}
```

Parse a line item from a decoded JSON map.

Accepts any map and extracts known fields. Fields with the wrong type are
`nil`. Unrecognized keys are kept in `extensions` for lossless
round-trips. `startDateTime` and `endDateTime` become `DateTime` structs in
UTC.

## Examples

    iex> {:ok, item} = Ltix.GradeService.LineItem.from_json(%{"label" => "Quiz 1", "scoreMaximum" => 100})
    iex> {item.label, item.score_maximum}
    {"Quiz 1", 100}

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

Serialize a line item to a map with camelCase string keys.

## Examples

    iex> item = %Ltix.GradeService.LineItem{label: "Quiz 1", score_maximum: 100}
    iex> map = Ltix.GradeService.LineItem.to_map(item)
    iex> {map["label"], map["scoreMaximum"]}
    {"Quiz 1", 100}

# `validate`

```elixir
@spec validate(t()) :: :ok | {:error, Exception.t()}
```

Validate that a line item has the required fields for publishing.

Checks that `label` is present and non-blank, that `score_maximum` is
a positive number, and that date times are `DateTime` structs.

## Examples

    iex> item = %Ltix.GradeService.LineItem{label: "Quiz 1", score_maximum: 100}
    iex> Ltix.GradeService.LineItem.validate(item)
    :ok

    iex> item = %Ltix.GradeService.LineItem{label: nil, score_maximum: 100}
    iex> {:error, error} = Ltix.GradeService.LineItem.validate(item)
    iex> Exception.message(error)
    "Ltix.GradeService.LineItem field :label is required [AGS §3.2.7]"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
