-- name: GetCustomer :one
SELECT * FROM customers
WHERE id = ? LIMIT 1;

-- name: ListCustomers :many
SELECT * FROM customers
ORDER BY name
LIMIT ? OFFSET ?;

-- name: CreateCustomer :execresult
INSERT INTO customers (
    name, trading_name, abn, created, notes, 
    discount_pricing_policies, payment_terms, 
    customer_category_id, url, country_id
) VALUES (
    ?, ?, ?, NOW(), ?, ?, ?, ?, ?, ?
);

-- name: UpdateCustomer :exec
UPDATE customers
SET name = ?,
    trading_name = ?,
    abn = ?,
    notes = ?,
    discount_pricing_policies = ?,
    payment_terms = ?,
    customer_category_id = ?,
    url = ?,
    country_id = ?
WHERE id = ?;

-- name: DeleteCustomer :exec
DELETE FROM customers
WHERE id = ?;

-- name: SearchCustomersByName :many
SELECT * FROM customers
WHERE name LIKE CONCAT('%', ?, '%')
   OR trading_name LIKE CONCAT('%', ?, '%')
ORDER BY name
LIMIT ? OFFSET ?;

-- name: GetCustomerByABN :one
SELECT * FROM customers
WHERE abn = ?
LIMIT 1;