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

package projectsqlc

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const getRequirementPhasePointer = `-- name: GetRequirementPhasePointer :one
SELECT requirement_id, phase, approved_artifact_id, approved_by, approved_at, updated_at
FROM requirement_phase_pointers
WHERE requirement_id = $1 AND phase = $2
`

type GetRequirementPhasePointerParams struct {
	RequirementID pgtype.UUID `json:"requirement_id"`
	Phase         string      `json:"phase"`
}

func (q *Queries) GetRequirementPhasePointer(ctx context.Context, arg GetRequirementPhasePointerParams) (RequirementPhasePointer, error) {
	row := q.db.QueryRow(ctx, getRequirementPhasePointer, arg.RequirementID, arg.Phase)
	var i RequirementPhasePointer
	err := row.Scan(
		&i.RequirementID,
		&i.Phase,
		&i.ApprovedArtifactID,
		&i.ApprovedBy,
		&i.ApprovedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const listRequirementPhasePointers = `-- name: ListRequirementPhasePointers :many
SELECT requirement_id, phase, approved_artifact_id, approved_by, approved_at, updated_at
FROM requirement_phase_pointers
WHERE requirement_id = $1
ORDER BY phase ASC
`

func (q *Queries) ListRequirementPhasePointers(ctx context.Context, requirementID pgtype.UUID) ([]RequirementPhasePointer, error) {
	rows, err := q.db.Query(ctx, listRequirementPhasePointers, requirementID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []RequirementPhasePointer
	for rows.Next() {
		var i RequirementPhasePointer
		if err := rows.Scan(
			&i.RequirementID,
			&i.Phase,
			&i.ApprovedArtifactID,
			&i.ApprovedBy,
			&i.ApprovedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const upsertRequirementPhasePointer = `-- name: UpsertRequirementPhasePointer :one
INSERT INTO requirement_phase_pointers (requirement_id, phase, approved_artifact_id, approved_by, approved_at, updated_at)
VALUES ($1, $2, $3, $4, now(), now())
ON CONFLICT (requirement_id, phase) DO UPDATE
  SET approved_artifact_id = EXCLUDED.approved_artifact_id,
      approved_by = EXCLUDED.approved_by,
      approved_at = EXCLUDED.approved_at,
      updated_at = now()
RETURNING requirement_id, phase, approved_artifact_id, approved_by, approved_at, updated_at
`

type UpsertRequirementPhasePointerParams struct {
	RequirementID      pgtype.UUID `json:"requirement_id"`
	Phase              string      `json:"phase"`
	ApprovedArtifactID pgtype.UUID `json:"approved_artifact_id"`
	ApprovedBy         pgtype.UUID `json:"approved_by"`
}

func (q *Queries) UpsertRequirementPhasePointer(ctx context.Context, arg UpsertRequirementPhasePointerParams) (RequirementPhasePointer, error) {
	row := q.db.QueryRow(ctx, upsertRequirementPhasePointer,
		arg.RequirementID,
		arg.Phase,
		arg.ApprovedArtifactID,
		arg.ApprovedBy,
	)
	var i RequirementPhasePointer
	err := row.Scan(
		&i.RequirementID,
		&i.Phase,
		&i.ApprovedArtifactID,
		&i.ApprovedBy,
		&i.ApprovedAt,
		&i.UpdatedAt,
	)
	return i, err
}
