defmodule NLdoc.Spec.TableHeader do @moduledoc """ This module defines the Ecto schema for the NLdoc spec TableHeader object. """ use NLdoc.Spec.Schema, type: "https://spec.nldoc.nl/Resource/TableHeader" typed_embedded_schema null: false do field :id, Ecto.UUID field :type, :string, default: @resource_type field :rowspan, :integer, default: 1 field :colspan, :integer, default: 1 field :abbreviation, :string, null: true field :scope, Ecto.Enum, values: [:row, :column], null: true field(:children, {:array, PolymorphicEmbed}, types: map(NLdoc.Spec.document_children()), type_field_name: :type, on_replace: :delete, default: [], array?: true ) :: [NLdoc.Spec.document_child()] field(:descriptors, {:array, PolymorphicEmbed}, types: map(NLdoc.Spec.descriptors()), type_field_name: :type, on_replace: :delete, default: [], array?: true ) :: [NLdoc.Spec.descriptor()] end def changeset(object, attrs) do object |> cast(attrs, [:id, :type, :rowspan, :colspan, :abbreviation, :scope], @cast_opts) |> cast_polymorphic_embed(:children, @cast_opts) |> cast_polymorphic_embed(:descriptors, @cast_opts) |> validate_required([:id, :type]) |> validate_inclusion(:type, [@resource_type]) |> validate_inclusion(:rowspan, 1..65_534) |> validate_inclusion(:colspan, 1..1000) end end