// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: channels.sql

package dbgen

import (
	"context"
	"database/sql"
)

const adminUpdateChannel = `-- name: AdminUpdateChannel :exec
UPDATE channels
SET name = ?, topic = ?, slow_mode = ?, position = ?, archived = ?
WHERE id = ?
`

type AdminUpdateChannelParams struct {
	Name     string  `json:"name"`
	Topic    *string `json:"topic"`
	SlowMode int64   `json:"slowMode"`
	Position int64   `json:"position"`
	Archived int64   `json:"archived"`
	ID       int64   `json:"id"`
}

func (q *Queries) AdminUpdateChannel(ctx context.Context, arg AdminUpdateChannelParams) error {
	_, err := q.db.ExecContext(ctx, adminUpdateChannel,
		arg.Name,
		arg.Topic,
		arg.SlowMode,
		arg.Position,
		arg.Archived,
		arg.ID,
	)
	return err
}

const createChannel = `-- name: CreateChannel :execresult
INSERT INTO channels (name, type, category, topic, position) VALUES (?, ?, ?, ?, ?)
`

type CreateChannelParams struct {
	Name     string  `json:"name"`
	Type     string  `json:"type"`
	Category *string `json:"category"`
	Topic    *string `json:"topic"`
	Position int64   `json:"position"`
}

func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (sql.Result, error) {
	return q.db.ExecContext(ctx, createChannel,
		arg.Name,
		arg.Type,
		arg.Category,
		arg.Topic,
		arg.Position,
	)
}

const deleteChannel = `-- name: DeleteChannel :exec
DELETE FROM channels WHERE id = ?
`

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

const deleteChannelPermission = `-- name: DeleteChannelPermission :exec
DELETE FROM channel_overrides WHERE channel_id = ? AND role_id = ?
`

type DeleteChannelPermissionParams struct {
	ChannelID int64 `json:"channelId"`
	RoleID    int64 `json:"roleId"`
}

func (q *Queries) DeleteChannelPermission(ctx context.Context, arg DeleteChannelPermissionParams) error {
	_, err := q.db.ExecContext(ctx, deleteChannelPermission, arg.ChannelID, arg.RoleID)
	return err
}

const getChannel = `-- name: GetChannel :one
SELECT id, name, type, COALESCE(category, '') AS category, COALESCE(topic, '') AS topic,
       position, slow_mode, archived, created_at,
       COALESCE(voice_max_users, 0) AS voice_max_users,
       voice_quality,
       mixing_threshold,
       COALESCE(voice_max_video, 0) AS voice_max_video
FROM channels WHERE id = ?
`

type GetChannelRow struct {
	ID              int64   `json:"id"`
	Name            string  `json:"name"`
	Type            string  `json:"type"`
	Category        string  `json:"category"`
	Topic           string  `json:"topic"`
	Position        int64   `json:"position"`
	SlowMode        int64   `json:"slowMode"`
	Archived        int64   `json:"archived"`
	CreatedAt       string  `json:"createdAt"`
	VoiceMaxUsers   int64   `json:"voiceMaxUsers"`
	VoiceQuality    *string `json:"voiceQuality"`
	MixingThreshold *int64  `json:"mixingThreshold"`
	VoiceMaxVideo   int64   `json:"voiceMaxVideo"`
}

func (q *Queries) GetChannel(ctx context.Context, id int64) (GetChannelRow, error) {
	row := q.db.QueryRowContext(ctx, getChannel, id)
	var i GetChannelRow
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Type,
		&i.Category,
		&i.Topic,
		&i.Position,
		&i.SlowMode,
		&i.Archived,
		&i.CreatedAt,
		&i.VoiceMaxUsers,
		&i.VoiceQuality,
		&i.MixingThreshold,
		&i.VoiceMaxVideo,
	)
	return i, err
}

const getChannelPermission = `-- name: GetChannelPermission :one
SELECT allow, deny FROM channel_overrides WHERE channel_id = ? AND role_id = ?
`

type GetChannelPermissionParams struct {
	ChannelID int64 `json:"channelId"`
	RoleID    int64 `json:"roleId"`
}

type GetChannelPermissionRow struct {
	Allow int64 `json:"allow"`
	Deny  int64 `json:"deny"`
}

func (q *Queries) GetChannelPermission(ctx context.Context, arg GetChannelPermissionParams) (GetChannelPermissionRow, error) {
	row := q.db.QueryRowContext(ctx, getChannelPermission, arg.ChannelID, arg.RoleID)
	var i GetChannelPermissionRow
	err := row.Scan(&i.Allow, &i.Deny)
	return i, err
}

const getRoleChannelPermissions = `-- name: GetRoleChannelPermissions :many
SELECT channel_id, allow, deny FROM channel_overrides WHERE role_id = ?
`

type GetRoleChannelPermissionsRow struct {
	ChannelID int64 `json:"channelId"`
	Allow     int64 `json:"allow"`
	Deny      int64 `json:"deny"`
}

func (q *Queries) GetRoleChannelPermissions(ctx context.Context, roleID int64) ([]GetRoleChannelPermissionsRow, error) {
	rows, err := q.db.QueryContext(ctx, getRoleChannelPermissions, roleID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetRoleChannelPermissionsRow{}
	for rows.Next() {
		var i GetRoleChannelPermissionsRow
		if err := rows.Scan(&i.ChannelID, &i.Allow, &i.Deny); 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 listChannels = `-- name: ListChannels :many
SELECT id, name, type, COALESCE(category, '') AS category, COALESCE(topic, '') AS topic,
       position, slow_mode, archived, created_at,
       COALESCE(voice_max_users, 0) AS voice_max_users,
       voice_quality,
       mixing_threshold,
       COALESCE(voice_max_video, 0) AS voice_max_video
FROM channels ORDER BY position ASC, id ASC
`

type ListChannelsRow struct {
	ID              int64   `json:"id"`
	Name            string  `json:"name"`
	Type            string  `json:"type"`
	Category        string  `json:"category"`
	Topic           string  `json:"topic"`
	Position        int64   `json:"position"`
	SlowMode        int64   `json:"slowMode"`
	Archived        int64   `json:"archived"`
	CreatedAt       string  `json:"createdAt"`
	VoiceMaxUsers   int64   `json:"voiceMaxUsers"`
	VoiceQuality    *string `json:"voiceQuality"`
	MixingThreshold *int64  `json:"mixingThreshold"`
	VoiceMaxVideo   int64   `json:"voiceMaxVideo"`
}

func (q *Queries) ListChannels(ctx context.Context) ([]ListChannelsRow, error) {
	rows, err := q.db.QueryContext(ctx, listChannels)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListChannelsRow{}
	for rows.Next() {
		var i ListChannelsRow
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Type,
			&i.Category,
			&i.Topic,
			&i.Position,
			&i.SlowMode,
			&i.Archived,
			&i.CreatedAt,
			&i.VoiceMaxUsers,
			&i.VoiceQuality,
			&i.MixingThreshold,
			&i.VoiceMaxVideo,
		); 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 setChannelSlowMode = `-- name: SetChannelSlowMode :exec
UPDATE channels SET slow_mode = ? WHERE id = ?
`

type SetChannelSlowModeParams struct {
	SlowMode int64 `json:"slowMode"`
	ID       int64 `json:"id"`
}

func (q *Queries) SetChannelSlowMode(ctx context.Context, arg SetChannelSlowModeParams) error {
	_, err := q.db.ExecContext(ctx, setChannelSlowMode, arg.SlowMode, arg.ID)
	return err
}

const setChannelVoiceMaxUsers = `-- name: SetChannelVoiceMaxUsers :exec
UPDATE channels SET voice_max_users = ? WHERE id = ?
`

type SetChannelVoiceMaxUsersParams struct {
	VoiceMaxUsers int64 `json:"voiceMaxUsers"`
	ID            int64 `json:"id"`
}

func (q *Queries) SetChannelVoiceMaxUsers(ctx context.Context, arg SetChannelVoiceMaxUsersParams) error {
	_, err := q.db.ExecContext(ctx, setChannelVoiceMaxUsers, arg.VoiceMaxUsers, arg.ID)
	return err
}

const updateChannel = `-- name: UpdateChannel :exec
UPDATE channels SET name = ?, topic = ?, slow_mode = ? WHERE id = ?
`

type UpdateChannelParams struct {
	Name     string  `json:"name"`
	Topic    *string `json:"topic"`
	SlowMode int64   `json:"slowMode"`
	ID       int64   `json:"id"`
}

func (q *Queries) UpdateChannel(ctx context.Context, arg UpdateChannelParams) error {
	_, err := q.db.ExecContext(ctx, updateChannel,
		arg.Name,
		arg.Topic,
		arg.SlowMode,
		arg.ID,
	)
	return err
}

const upsertChannelPermission = `-- name: UpsertChannelPermission :exec
INSERT INTO channel_overrides (channel_id, role_id, allow, deny)
VALUES (?, ?, ?, ?)
ON CONFLICT(channel_id, role_id) DO UPDATE SET
    allow = excluded.allow,
    deny  = excluded.deny
`

type UpsertChannelPermissionParams struct {
	ChannelID int64 `json:"channelId"`
	RoleID    int64 `json:"roleId"`
	Allow     int64 `json:"allow"`
	Deny      int64 `json:"deny"`
}

func (q *Queries) UpsertChannelPermission(ctx context.Context, arg UpsertChannelPermissionParams) error {
	_, err := q.db.ExecContext(ctx, upsertChannelPermission,
		arg.ChannelID,
		arg.RoleID,
		arg.Allow,
		arg.Deny,
	)
	return err
}
