// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.28.0
// source: broadcast.sql

package db

import (
	"context"

	"github.com/lib/pq"
)

const createProcessBroadCast = `-- name: CreateProcessBroadCast :one
INSERT INTO process_broadcast (
    process,
    emails,
    status
 ) VALUES (
    $1, 
    $2,
    $3
 ) RETURNING id, process, emails, status, created_at
`

type CreateProcessBroadCastParams struct {
	Process string   `json:"process"`
	Emails  []string `json:"emails"`
	Status  string   `json:"status"`
}

func (q *Queries) CreateProcessBroadCast(ctx context.Context, arg CreateProcessBroadCastParams) (ProcessBroadcast, error) {
	row := q.db.QueryRowContext(ctx, createProcessBroadCast, arg.Process, pq.Array(arg.Emails), arg.Status)
	var i ProcessBroadcast
	err := row.Scan(
		&i.ID,
		&i.Process,
		pq.Array(&i.Emails),
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const createUserBroadCast = `-- name: CreateUserBroadCast :one
INSERT INTO user_broadcast (
    usertype,
    message
 ) VALUES (
    $1, $2
 ) RETURNING id, usertype, message, created_at
`

type CreateUserBroadCastParams struct {
	Usertype []string `json:"usertype"`
	Message  string   `json:"message"`
}

func (q *Queries) CreateUserBroadCast(ctx context.Context, arg CreateUserBroadCastParams) (UserBroadcast, error) {
	row := q.db.QueryRowContext(ctx, createUserBroadCast, pq.Array(arg.Usertype), arg.Message)
	var i UserBroadcast
	err := row.Scan(
		&i.ID,
		pq.Array(&i.Usertype),
		&i.Message,
		&i.CreatedAt,
	)
	return i, err
}

const deleteProcessBroadCast = `-- name: DeleteProcessBroadCast :exec
DELETE FROM process_broadcast WHERE id= $1
`

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

const deleteUserBroadCast = `-- name: DeleteUserBroadCast :exec
DELETE FROM user_broadcast WHERE id= $1
`

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

const getEmailsOnProcessBroadCast = `-- name: GetEmailsOnProcessBroadCast :one
SELECT emails from process_broadcast where 
status = $1 AND process = $2
`

type GetEmailsOnProcessBroadCastParams struct {
	Status  string `json:"status"`
	Process string `json:"process"`
}

func (q *Queries) GetEmailsOnProcessBroadCast(ctx context.Context, arg GetEmailsOnProcessBroadCastParams) ([]string, error) {
	row := q.db.QueryRowContext(ctx, getEmailsOnProcessBroadCast, arg.Status, arg.Process)
	var emails []string
	err := row.Scan(pq.Array(&emails))
	return emails, err
}

const listProcessBroadCasts = `-- name: ListProcessBroadCasts :many
SELECT id, process, emails, status, created_at from process_broadcast
ORDER BY id DESC 
LIMIT $1
OFFSET $2
`

type ListProcessBroadCastsParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListProcessBroadCasts(ctx context.Context, arg ListProcessBroadCastsParams) ([]ProcessBroadcast, error) {
	rows, err := q.db.QueryContext(ctx, listProcessBroadCasts, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ProcessBroadcast{}
	for rows.Next() {
		var i ProcessBroadcast
		if err := rows.Scan(
			&i.ID,
			&i.Process,
			pq.Array(&i.Emails),
			&i.Status,
			&i.CreatedAt,
		); 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 listUserBroadCasts = `-- name: ListUserBroadCasts :many
SELECT id, usertype, message, created_at from user_broadcast
ORDER BY id DESC LIMIT $1
OFFSET $2
`

type ListUserBroadCastsParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListUserBroadCasts(ctx context.Context, arg ListUserBroadCastsParams) ([]UserBroadcast, error) {
	rows, err := q.db.QueryContext(ctx, listUserBroadCasts, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []UserBroadcast{}
	for rows.Next() {
		var i UserBroadcast
		if err := rows.Scan(
			&i.ID,
			pq.Array(&i.Usertype),
			&i.Message,
			&i.CreatedAt,
		); 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
}
