// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: project_sync_settings.sql

package db

import (
	"context"
)

const createProjectSyncSetting = `-- 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
`

type CreateProjectSyncSettingParams struct {
	Provider          string `json:"provider"`
	Tenant            string `json:"tenant"`
	Project           string `json:"project"`
	GitRemoteUrl      string `json:"git_remote_url"`
	SourceBranch      string `json:"source_branch"`
	WorkspaceID       string `json:"workspace_id"`
	WorkspaceBasePath string `json:"workspace_base_path"`
	RepoDirName       string `json:"repo_dir_name"`
}

func (q *Queries) CreateProjectSyncSetting(ctx context.Context, arg CreateProjectSyncSettingParams) (ProjectSyncSetting, error) {
	row := q.db.QueryRow(ctx, createProjectSyncSetting,
		arg.Provider,
		arg.Tenant,
		arg.Project,
		arg.GitRemoteUrl,
		arg.SourceBranch,
		arg.WorkspaceID,
		arg.WorkspaceBasePath,
		arg.RepoDirName,
	)
	var i ProjectSyncSetting
	err := row.Scan(
		&i.ID,
		&i.Provider,
		&i.Tenant,
		&i.Project,
		&i.GitRemoteUrl,
		&i.SourceBranch,
		&i.WorkspaceID,
		&i.WorkspaceBasePath,
		&i.RepoDirName,
		&i.Active,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const deactivateProjectSyncSetting = `-- 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
`

type DeactivateProjectSyncSettingParams struct {
	Provider string `json:"provider"`
	Tenant   string `json:"tenant"`
	Project  string `json:"project"`
}

func (q *Queries) DeactivateProjectSyncSetting(ctx context.Context, arg DeactivateProjectSyncSettingParams) (ProjectSyncSetting, error) {
	row := q.db.QueryRow(ctx, deactivateProjectSyncSetting, arg.Provider, arg.Tenant, arg.Project)
	var i ProjectSyncSetting
	err := row.Scan(
		&i.ID,
		&i.Provider,
		&i.Tenant,
		&i.Project,
		&i.GitRemoteUrl,
		&i.SourceBranch,
		&i.WorkspaceID,
		&i.WorkspaceBasePath,
		&i.RepoDirName,
		&i.Active,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getActiveProjectSyncSettingByTarget = `-- 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
`

type GetActiveProjectSyncSettingByTargetParams struct {
	Provider string `json:"provider"`
	Tenant   string `json:"tenant"`
	Project  string `json:"project"`
}

func (q *Queries) GetActiveProjectSyncSettingByTarget(ctx context.Context, arg GetActiveProjectSyncSettingByTargetParams) (ProjectSyncSetting, error) {
	row := q.db.QueryRow(ctx, getActiveProjectSyncSettingByTarget, arg.Provider, arg.Tenant, arg.Project)
	var i ProjectSyncSetting
	err := row.Scan(
		&i.ID,
		&i.Provider,
		&i.Tenant,
		&i.Project,
		&i.GitRemoteUrl,
		&i.SourceBranch,
		&i.WorkspaceID,
		&i.WorkspaceBasePath,
		&i.RepoDirName,
		&i.Active,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
