# Script for populating the database. You can run it as:
#
#     mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
#     Todoit.Repo.insert!(%Todoit.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.

alias Todoit.Todo.Task

tasks = [
  %{title: "Buy groceries", description: "Milk, Bread, Eggs", done: false},
  %{title: "Finish Elixir project", description: "Complete the Todoit app", done: true},
  %{title: "Workout", description: "Gym session for 1 hour", done: false},
  %{title: "Call mom", description: "Check in with family", done: true},
  %{title: "Pay bills", description: "Electricity and Internet", done: false},
  %{title: "Read a book", description: "Finish 20 pages of 'Elixir in Action'", done: false},
  %{title: "Write blog post", description: "Topic: Intro to Ash Framework", done: true},
  %{title: "Plan weekend trip", description: "Decide on location and budget", done: false},
  %{title: "Team meeting", description: "Discuss progress on project", done: true},
  %{title: "Organize desk", description: "Clean workspace and sort documents", done: false},
  %{title: "Backup laptop", description: "Run system backup", done: false},
  %{title: "Dentist appointment", description: "Routine check-up", done: true},
  %{title: "Buy new headphones", description: "Check best deals online", done: false},
  %{title: "Water plants", description: "Living room and balcony plants", done: true},
  %{title: "Update resume", description: "Add recent Elixir projects", done: false},
  %{title: "Client follow-up", description: "Send update email", done: true},
  %{title: "Cook dinner", description: "Try new pasta recipe", done: false},
  %{title: "Go for a walk", description: "Evening stroll in the park", done: true},
  %{title: "Learn Tailwind", description: "Practice layouts with LiveView", done: false},
  %{title: "Fix bike", description: "Repair flat tire", done: false}
]

for attrs <- tasks do
  case Ash.create(Task, attrs, authorize?: false) do
    {:ok, task} ->
      IO.puts("✅ Created: #{task.title}")

    {:error, error} ->
      IO.inspect(error, label: "❌ Error creating task")
  end
end
