-- name: GetRoadmapSyncIdentityByWorkItem :one
SELECT id, shape, roadmap_milestone_path, roadmap_item_id, provider, tenant, project, work_item_id, parent_work_item_id, provider_revision, roadmap_revision, created_at, updated_at
FROM roadmap_sync_identities
WHERE provider = $1 AND tenant = $2 AND project = $3 AND work_item_id = $4;

-- name: GetRoadmapSyncIdentityByMilestonePath :one
SELECT id, shape, roadmap_milestone_path, roadmap_item_id, provider, tenant, project, work_item_id, parent_work_item_id, provider_revision, roadmap_revision, created_at, updated_at
FROM roadmap_sync_identities
WHERE roadmap_milestone_path = $1;

-- name: UpsertRoadmapSyncIdentityByWorkItem :one
INSERT INTO roadmap_sync_identities (
    shape, roadmap_milestone_path, roadmap_item_id, provider, tenant, project, work_item_id, parent_work_item_id, provider_revision, roadmap_revision
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
ON CONFLICT (provider, tenant, project, work_item_id)
DO UPDATE SET
    shape = EXCLUDED.shape,
    roadmap_item_id = EXCLUDED.roadmap_item_id,
    parent_work_item_id = EXCLUDED.parent_work_item_id,
    provider_revision = EXCLUDED.provider_revision,
    roadmap_revision = EXCLUDED.roadmap_revision,
    updated_at = now()
WHERE roadmap_sync_identities.roadmap_milestone_path = EXCLUDED.roadmap_milestone_path
RETURNING id, shape, roadmap_milestone_path, roadmap_item_id, provider, tenant, project, work_item_id, parent_work_item_id, provider_revision, roadmap_revision, created_at, updated_at;
