-- name: CreateDeal :exec
INSERT INTO deals (id, tenant_id, title, account_id, contact_id, pipeline_id, stage_id, value_cents, currency, status, source, expected_close_date, created_at, updated_at)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);

-- name: UpdateDeal :exec
UPDATE deals
SET title=$1, stage_id=$2, value_cents=$3, currency=$4, source=$5, expected_close_date=$6, updated_at=$7
WHERE tenant_id=$8 AND id=$9;

-- name: GetDeal :one
SELECT * FROM deals WHERE tenant_id=$1 AND id=$2;

-- name: ListDeals :many
SELECT * FROM deals WHERE tenant_id=$1 ORDER BY created_at DESC;

-- name: MoveDealStage :exec
UPDATE deals SET stage_id=$1, updated_at=$2 WHERE tenant_id=$3 AND id=$4;

-- name: CloseDeal :exec
UPDATE deals SET status=$1, closed_at=$2, updated_at=$3 WHERE tenant_id=$4 AND id=$5;
