// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: query.sql

package querytest

import (
	"context"

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

const updateUserAddressWithAddress = `-- name: UpdateUserAddressWithAddress :one
WITH t1 AS (
    UPDATE "address" as a
    SET
    address_line = COALESCE($1,address_line), 
    region = COALESCE($2,region), 
    city= COALESCE($3,city)
    WHERE id = COALESCE($4,id)
    RETURNING a.id, a.address_line, a.region, a.city
   ),
   
    t2 AS (
    UPDATE "user_address"
    SET
    default_address = COALESCE($5,default_address)
    WHERE
    user_id = COALESCE($6,user_id)
    AND address_id = COALESCE($7,address_id)
    RETURNING user_id, address_id, default_address
	)
	
SELECT 
user_id,
address_id,
default_address,
address_line,
region,
city From t1,t2
`

type UpdateUserAddressWithAddressParams struct {
	AddressLine    pgtype.Text
	Region         pgtype.Text
	City           pgtype.Text
	ID             pgtype.Int8
	DefaultAddress pgtype.Int8
	UserID         pgtype.Int8
	AddressID      pgtype.Int8
}

type UpdateUserAddressWithAddressRow struct {
	UserID         int64
	AddressID      int64
	DefaultAddress pgtype.Int8
	AddressLine    string
	Region         string
	City           string
}

func (q *Queries) UpdateUserAddressWithAddress(ctx context.Context, arg UpdateUserAddressWithAddressParams) (UpdateUserAddressWithAddressRow, error) {
	row := q.db.QueryRow(ctx, updateUserAddressWithAddress,
		arg.AddressLine,
		arg.Region,
		arg.City,
		arg.ID,
		arg.DefaultAddress,
		arg.UserID,
		arg.AddressID,
	)
	var i UpdateUserAddressWithAddressRow
	err := row.Scan(
		&i.UserID,
		&i.AddressID,
		&i.DefaultAddress,
		&i.AddressLine,
		&i.Region,
		&i.City,
	)
	return i, err
}
