defmodule Zoeyscomputer.Images.Image do
  use Ecto.Schema
  import Ecto.Changeset

  @derive {Jason.Encoder, only: [:id, :file, :inserted_at, :updated_at]}

  schema "images" do
    field(:file, :string)
    belongs_to :user, Zoeyscomputer.Users.User

    timestamps(type: :utc_datetime)
  end

  @doc false
  def changeset(image, attrs) do
    image
    |> cast(attrs, [:file, :user_id])
    |> validate_required([:file, :user_id])
  end
end
