-- name: CreateProjectSyncSetting :one
INSERT INTO project_sync_settings (
    provider, tenant, project, git_remote_url, source_branch,
    workspace_id, workspace_base_path, repo_dir_name, active
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, TRUE)
RETURNING id, provider, tenant, project, git_remote_url, source_branch,
          workspace_id, workspace_base_path, repo_dir_name, active,
          created_at, updated_at;

-- name: GetActiveProjectSyncSettingByTarget :one
SELECT id, provider, tenant, project, git_remote_url, source_branch,
       workspace_id, workspace_base_path, repo_dir_name, active,
       created_at, updated_at
FROM project_sync_settings
WHERE provider = $1 AND tenant = $2 AND project = $3 AND active = TRUE;

-- name: DeactivateProjectSyncSetting :one
UPDATE project_sync_settings
SET active = FALSE, updated_at = now()
WHERE provider = $1 AND tenant = $2 AND project = $3 AND active = TRUE
RETURNING id, provider, tenant, project, git_remote_url, source_branch,
          workspace_id, workspace_base_path, repo_dir_name, active,
          created_at, updated_at;
