// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: cashier.sql

package dbgen

import (
	"context"

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

const GetAllCashiers = `-- name: GetAllCashiers :many
SELECT users.id, users.first_name, users.last_name, users.email, users.phone_number, users.role, users.password, users.email_verified, users.phone_verified, users.created_at, users.updated_at, users.company_id, users.suspended_at, users.suspended, users.referral_code, users.referred_by,
    branch_id,
    branches.name AS branch_name,
    branches.wallet_id AS branch_wallet,
    branches.location As branch_location
FROM branch_cashiers
    JOIN users ON branch_cashiers.user_id = users.id
    JOIN branches ON branches.id = branch_id
`

type GetAllCashiersRow struct {
	ID             int64              `json:"id"`
	FirstName      string             `json:"first_name"`
	LastName       string             `json:"last_name"`
	Email          pgtype.Text        `json:"email"`
	PhoneNumber    pgtype.Text        `json:"phone_number"`
	Role           string             `json:"role"`
	Password       []byte             `json:"password"`
	EmailVerified  bool               `json:"email_verified"`
	PhoneVerified  bool               `json:"phone_verified"`
	CreatedAt      pgtype.Timestamptz `json:"created_at"`
	UpdatedAt      pgtype.Timestamptz `json:"updated_at"`
	CompanyID      pgtype.Int8        `json:"company_id"`
	SuspendedAt    pgtype.Timestamptz `json:"suspended_at"`
	Suspended      bool               `json:"suspended"`
	ReferralCode   pgtype.Text        `json:"referral_code"`
	ReferredBy     pgtype.Text        `json:"referred_by"`
	BranchID       int64              `json:"branch_id"`
	BranchName     string             `json:"branch_name"`
	BranchWallet   int64              `json:"branch_wallet"`
	BranchLocation string             `json:"branch_location"`
}

func (q *Queries) GetAllCashiers(ctx context.Context) ([]GetAllCashiersRow, error) {
	rows, err := q.db.Query(ctx, GetAllCashiers)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetAllCashiersRow
	for rows.Next() {
		var i GetAllCashiersRow
		if err := rows.Scan(
			&i.ID,
			&i.FirstName,
			&i.LastName,
			&i.Email,
			&i.PhoneNumber,
			&i.Role,
			&i.Password,
			&i.EmailVerified,
			&i.PhoneVerified,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.CompanyID,
			&i.SuspendedAt,
			&i.Suspended,
			&i.ReferralCode,
			&i.ReferredBy,
			&i.BranchID,
			&i.BranchName,
			&i.BranchWallet,
			&i.BranchLocation,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const GetCashierByID = `-- name: GetCashierByID :one
SELECT users.id, users.first_name, users.last_name, users.email, users.phone_number, users.role, users.password, users.email_verified, users.phone_verified, users.created_at, users.updated_at, users.company_id, users.suspended_at, users.suspended, users.referral_code, users.referred_by,
    branch_id,
    branches.name AS branch_name,
    branches.wallet_id AS branch_wallet,
    branches.location As branch_location
FROM branch_cashiers
    JOIN users ON branch_cashiers.user_id = users.id
    JOIN branches ON branches.id = branch_id
WHERE users.id = $1
`

type GetCashierByIDRow struct {
	ID             int64              `json:"id"`
	FirstName      string             `json:"first_name"`
	LastName       string             `json:"last_name"`
	Email          pgtype.Text        `json:"email"`
	PhoneNumber    pgtype.Text        `json:"phone_number"`
	Role           string             `json:"role"`
	Password       []byte             `json:"password"`
	EmailVerified  bool               `json:"email_verified"`
	PhoneVerified  bool               `json:"phone_verified"`
	CreatedAt      pgtype.Timestamptz `json:"created_at"`
	UpdatedAt      pgtype.Timestamptz `json:"updated_at"`
	CompanyID      pgtype.Int8        `json:"company_id"`
	SuspendedAt    pgtype.Timestamptz `json:"suspended_at"`
	Suspended      bool               `json:"suspended"`
	ReferralCode   pgtype.Text        `json:"referral_code"`
	ReferredBy     pgtype.Text        `json:"referred_by"`
	BranchID       int64              `json:"branch_id"`
	BranchName     string             `json:"branch_name"`
	BranchWallet   int64              `json:"branch_wallet"`
	BranchLocation string             `json:"branch_location"`
}

func (q *Queries) GetCashierByID(ctx context.Context, id int64) (GetCashierByIDRow, error) {
	row := q.db.QueryRow(ctx, GetCashierByID, id)
	var i GetCashierByIDRow
	err := row.Scan(
		&i.ID,
		&i.FirstName,
		&i.LastName,
		&i.Email,
		&i.PhoneNumber,
		&i.Role,
		&i.Password,
		&i.EmailVerified,
		&i.PhoneVerified,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.CompanyID,
		&i.SuspendedAt,
		&i.Suspended,
		&i.ReferralCode,
		&i.ReferredBy,
		&i.BranchID,
		&i.BranchName,
		&i.BranchWallet,
		&i.BranchLocation,
	)
	return i, err
}

const GetCashiersByBranch = `-- name: GetCashiersByBranch :many
SELECT users.id, users.first_name, users.last_name, users.email, users.phone_number, users.role, users.password, users.email_verified, users.phone_verified, users.created_at, users.updated_at, users.company_id, users.suspended_at, users.suspended, users.referral_code, users.referred_by
FROM branch_cashiers
    JOIN users ON branch_cashiers.user_id = users.id
    JOIN branches ON branches.id = branch_id
WHERE branch_cashiers.branch_id = $1
`

func (q *Queries) GetCashiersByBranch(ctx context.Context, branchID int64) ([]User, error) {
	rows, err := q.db.Query(ctx, GetCashiersByBranch, branchID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []User
	for rows.Next() {
		var i User
		if err := rows.Scan(
			&i.ID,
			&i.FirstName,
			&i.LastName,
			&i.Email,
			&i.PhoneNumber,
			&i.Role,
			&i.Password,
			&i.EmailVerified,
			&i.PhoneVerified,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.CompanyID,
			&i.SuspendedAt,
			&i.Suspended,
			&i.ReferralCode,
			&i.ReferredBy,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
