-- name: UpsertContainer :exec
INSERT INTO containers (
  user_id, container_id, container_name, image, status, namespace, auto_start,
  host_path, container_path, last_started_at, last_stopped_at
)
VALUES (
  sqlc.arg(user_id),
  sqlc.arg(container_id),
  sqlc.arg(container_name),
  sqlc.arg(image),
  sqlc.arg(status),
  sqlc.arg(namespace),
  sqlc.arg(auto_start),
  sqlc.arg(host_path),
  sqlc.arg(container_path),
  sqlc.arg(last_started_at),
  sqlc.arg(last_stopped_at)
)
ON CONFLICT (container_id) DO UPDATE SET
  user_id = EXCLUDED.user_id,
  container_name = EXCLUDED.container_name,
  image = EXCLUDED.image,
  status = EXCLUDED.status,
  namespace = EXCLUDED.namespace,
  auto_start = EXCLUDED.auto_start,
  host_path = EXCLUDED.host_path,
  container_path = EXCLUDED.container_path,
  last_started_at = EXCLUDED.last_started_at,
  last_stopped_at = EXCLUDED.last_stopped_at,
  updated_at = now();

-- name: GetContainerByContainerID :one
SELECT * FROM containers WHERE container_id = sqlc.arg(container_id);
