       nil ->
         generate_slug()
         |> (&put_change(changeset, :slug, &1)).()
+
       _ ->
         changeset
     end


  @params ~w(title body developer_id channel_id likes max_likes)a
  def permitted_params, do: @params
  def required_params,  do: @params

  schema "posts" do
    field :title, :string
    field :body, :string
    field :slug, :string
    field :likes, :integer, default: 1
    field :max_likes, :integer, default: 1
    field :tweeted_at, :utc_datetime

    belongs_to :channel, Channel
    belongs_to :developer, Developer

    timestamps()
  end


  def slugified_title(title) do
    title
    |> String.downcase()
    |> String.replace(~r/[^A-Za-z0-9\s-]/, "")
    |> String.replace(~r/(\s|-)+/, "-")
  end
