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

package dbgen

import (
	"context"

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

const CreateCompany = `-- name: CreateCompany :one
INSERT INTO companies (
        name,
        admin_id,
        wallet_id
    )
VALUES ($1, $2, $3)
RETURNING id, name, admin_id, wallet_id
`

type CreateCompanyParams struct {
	Name     string `json:"name"`
	AdminID  int64  `json:"admin_id"`
	WalletID int64  `json:"wallet_id"`
}

func (q *Queries) CreateCompany(ctx context.Context, arg CreateCompanyParams) (Company, error) {
	row := q.db.QueryRow(ctx, CreateCompany, arg.Name, arg.AdminID, arg.WalletID)
	var i Company
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.AdminID,
		&i.WalletID,
	)
	return i, err
}

const DeleteCompany = `-- name: DeleteCompany :exec
DELETE FROM companies
WHERE id = $1
`

func (q *Queries) DeleteCompany(ctx context.Context, id int64) error {
	_, err := q.db.Exec(ctx, DeleteCompany, id)
	return err
}

const GetAllCompanies = `-- name: GetAllCompanies :many
SELECT id, name, admin_id, wallet_id, balance, is_active, admin_first_name, admin_last_name, admin_phone_number
FROM companies_details
`

func (q *Queries) GetAllCompanies(ctx context.Context) ([]CompaniesDetail, error) {
	rows, err := q.db.Query(ctx, GetAllCompanies)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []CompaniesDetail
	for rows.Next() {
		var i CompaniesDetail
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.AdminID,
			&i.WalletID,
			&i.Balance,
			&i.IsActive,
			&i.AdminFirstName,
			&i.AdminLastName,
			&i.AdminPhoneNumber,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const GetCompanyByID = `-- name: GetCompanyByID :one
SELECT id, name, admin_id, wallet_id, balance, is_active, admin_first_name, admin_last_name, admin_phone_number
FROM companies_details
WHERE id = $1
`

func (q *Queries) GetCompanyByID(ctx context.Context, id int64) (CompaniesDetail, error) {
	row := q.db.QueryRow(ctx, GetCompanyByID, id)
	var i CompaniesDetail
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.AdminID,
		&i.WalletID,
		&i.Balance,
		&i.IsActive,
		&i.AdminFirstName,
		&i.AdminLastName,
		&i.AdminPhoneNumber,
	)
	return i, err
}

const SearchCompanyByName = `-- name: SearchCompanyByName :many
SELECT id, name, admin_id, wallet_id, balance, is_active, admin_first_name, admin_last_name, admin_phone_number
FROM companies_details
WHERE name ILIKE '%' || $1 || '%'
`

func (q *Queries) SearchCompanyByName(ctx context.Context, dollar_1 pgtype.Text) ([]CompaniesDetail, error) {
	rows, err := q.db.Query(ctx, SearchCompanyByName, dollar_1)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []CompaniesDetail
	for rows.Next() {
		var i CompaniesDetail
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.AdminID,
			&i.WalletID,
			&i.Balance,
			&i.IsActive,
			&i.AdminFirstName,
			&i.AdminLastName,
			&i.AdminPhoneNumber,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const UpdateCompany = `-- name: UpdateCompany :one
UPDATE companies
SET name = COALESCE($2, name),
    admin_id = COALESCE($3, admin_id)
WHERE id = $1
RETURNING id, name, admin_id, wallet_id
`

type UpdateCompanyParams struct {
	ID      int64       `json:"id"`
	Name    pgtype.Text `json:"name"`
	AdminID pgtype.Int8 `json:"admin_id"`
}

func (q *Queries) UpdateCompany(ctx context.Context, arg UpdateCompanyParams) (Company, error) {
	row := q.db.QueryRow(ctx, UpdateCompany, arg.ID, arg.Name, arg.AdminID)
	var i Company
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.AdminID,
		&i.WalletID,
	)
	return i, err
}
