// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.17.2
// source: suppliers.sql

package db

import (
	"context"

	"github.com/google/uuid"
	"github.com/tabbed/pqtype"
)

const createSuppliers = `-- name: CreateSuppliers :one
INSERT INTO suppliers (
  merchant_id, 
  name,
  detail
) VALUES (
  $1, $2, $3
)
RETURNING id, index_id, merchant_id, name, detail, created_at, updated_at
`

type CreateSuppliersParams struct {
	MerchantID uuid.UUID             `json:"merchant_id"`
	Name       string                `json:"name"`
	Detail     pqtype.NullRawMessage `json:"detail"`
}

func (q *Queries) CreateSuppliers(ctx context.Context, arg CreateSuppliersParams) (Supplier, error) {
	row := q.db.QueryRowContext(ctx, createSuppliers, arg.MerchantID, arg.Name, arg.Detail)
	var i Supplier
	err := row.Scan(
		&i.ID,
		&i.IndexID,
		&i.MerchantID,
		&i.Name,
		&i.Detail,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const deleteSupplier = `-- name: DeleteSupplier :exec
DELETE FROM suppliers where id = $1
`

func (q *Queries) DeleteSupplier(ctx context.Context, id uuid.UUID) error {
	_, err := q.db.ExecContext(ctx, deleteSupplier, id)
	return err
}

const suppliersList = `-- name: SuppliersList :many
SELECT id, index_id, merchant_id, name, detail, created_at, updated_at FROM suppliers
WHERE merchant_id = $1
ORDER BY index_id
LIMIT $2
OFFSET $3
`

type SuppliersListParams struct {
	MerchantID uuid.UUID `json:"merchant_id"`
	Limit      int32     `json:"limit"`
	Offset     int32     `json:"offset"`
}

func (q *Queries) SuppliersList(ctx context.Context, arg SuppliersListParams) ([]Supplier, error) {
	rows, err := q.db.QueryContext(ctx, suppliersList, arg.MerchantID, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Supplier{}
	for rows.Next() {
		var i Supplier
		if err := rows.Scan(
			&i.ID,
			&i.IndexID,
			&i.MerchantID,
			&i.Name,
			&i.Detail,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateSupplier = `-- name: UpdateSupplier :one
SELECT id, index_id, merchant_id, name, detail, created_at, updated_at FROM suppliers
WHERE id = $1
`

func (q *Queries) UpdateSupplier(ctx context.Context, id uuid.UUID) (Supplier, error) {
	row := q.db.QueryRowContext(ctx, updateSupplier, id)
	var i Supplier
	err := row.Scan(
		&i.ID,
		&i.IndexID,
		&i.MerchantID,
		&i.Name,
		&i.Detail,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}