-- name: ListActors :many
SELECT actor_id, first_name, last_name, last_update
FROM actor
ORDER BY actor_id ASC
LIMIT ? OFFSET ?;

-- name: CountActors :one
SELECT COUNT(*)
FROM actor;

-- name: GetActor :one
SELECT actor_id, first_name, last_name, last_update
FROM actor
WHERE actor_id = ?;

-- name: ListFilmsByActor :many
SELECT f.film_id,
       f.title,
       f.description,
       f.release_year,
       f.language_id,
       f.original_language_id,
       f.rental_duration,
       f.rental_rate,
       f.length,
       f.replacement_cost,
       f.rating,
       f.special_features,
       f.last_update
FROM film f
         JOIN film_actor fa ON fa.film_id = f.film_id
WHERE fa.actor_id = ?
ORDER BY f.title ASC;

-- name: NextActorID :one
SELECT COALESCE(MAX(actor_id), 0) + 1 FROM actor;

-- name: InsertActor :exec
INSERT INTO actor (actor_id, first_name, last_name, last_update)
VALUES (?, ?, ?, CURRENT_TIMESTAMP);

-- name: UpdateActorPut :execrows
UPDATE actor
SET first_name = ?,
    last_name  = ?
WHERE actor_id = ?;

-- name: PatchActor :execrows
UPDATE actor
SET first_name = COALESCE(sqlc.narg(first_name), first_name),
    last_name  = COALESCE(sqlc.narg(last_name),  last_name)
WHERE actor_id = sqlc.arg(actor_id);

-- name: DeleteActor :execrows
DELETE FROM actor WHERE actor_id = ?;
