defmodule Chklst.Accounts.Org do
  use Ecto.Schema
  import Ecto.Changeset

  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id
  schema "orgs" do
    field :name, :string
    field :status, Ecto.Enum, values: [:active, :suspended, :closed]

    many_to_many :users, Chklst.Accounts.User, join_through: Chklst.Accounts.UserOrg

    timestamps(type: :utc_datetime)
  end

  @doc false
  def changeset(org, attrs) do
    org
    |> cast(attrs, [:name, :status])
    |> validate_required([:name, :status])
  end
end