-- name: ListCategories :many
SELECT category_id, name, last_update
FROM category
ORDER BY category_id ASC
LIMIT ? OFFSET ?;

-- name: CountCategories :one
SELECT COUNT(*) FROM category;

-- name: GetCategory :one
SELECT category_id, name, last_update
FROM category
WHERE category_id = ?;

-- name: ListFilmsByCategoryName :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_category fc ON fc.film_id = f.film_id
JOIN category c ON c.category_id = fc.category_id
WHERE UPPER(c.name) = UPPER(?)
ORDER BY f.film_id ASC
LIMIT ? OFFSET ?;

-- name: CountFilmsByCategoryName :one
SELECT COUNT(*)
FROM film f
JOIN film_category fc ON fc.film_id = f.film_id
JOIN category c ON c.category_id = fc.category_id
WHERE UPPER(c.name) = UPPER(?);
