// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: backup.sql

package db

import (
	"context"

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

const getAgentByWorkspaceAndName = `-- name: GetAgentByWorkspaceAndName :one

SELECT id, workspace_id, name, avatar_url, runtime_mode, runtime_config, visibility, status, max_concurrent_tasks, owner_id, created_at, updated_at, description, runtime_id, instructions, archived_at, archived_by, custom_env, custom_args, mcp_config, model, thinking_level FROM agent
WHERE workspace_id = $1 AND name = $2
`

type GetAgentByWorkspaceAndNameParams struct {
	WorkspaceID pgtype.UUID `json:"workspace_id"`
	Name        string      `json:"name"`
}

// Backup & Restore queries
func (q *Queries) GetAgentByWorkspaceAndName(ctx context.Context, arg GetAgentByWorkspaceAndNameParams) (Agent, error) {
	row := q.db.QueryRow(ctx, getAgentByWorkspaceAndName, arg.WorkspaceID, arg.Name)
	var i Agent
	err := row.Scan(
		&i.ID,
		&i.WorkspaceID,
		&i.Name,
		&i.AvatarUrl,
		&i.RuntimeMode,
		&i.RuntimeConfig,
		&i.Visibility,
		&i.Status,
		&i.MaxConcurrentTasks,
		&i.OwnerID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Description,
		&i.RuntimeID,
		&i.Instructions,
		&i.ArchivedAt,
		&i.ArchivedBy,
		&i.CustomEnv,
		&i.CustomArgs,
		&i.McpConfig,
		&i.Model,
		&i.ThinkingLevel,
	)
	return i, err
}

const getMemberByEmailAndWorkspace = `-- name: GetMemberByEmailAndWorkspace :one
SELECT m.id, m.workspace_id, m.user_id, m.role, m.created_at FROM member m
JOIN "user" u ON u.id = m.user_id
WHERE u.email = $1 AND m.workspace_id = $2
`

type GetMemberByEmailAndWorkspaceParams struct {
	Email       string      `json:"email"`
	WorkspaceID pgtype.UUID `json:"workspace_id"`
}

func (q *Queries) GetMemberByEmailAndWorkspace(ctx context.Context, arg GetMemberByEmailAndWorkspaceParams) (Member, error) {
	row := q.db.QueryRow(ctx, getMemberByEmailAndWorkspace, arg.Email, arg.WorkspaceID)
	var i Member
	err := row.Scan(
		&i.ID,
		&i.WorkspaceID,
		&i.UserID,
		&i.Role,
		&i.CreatedAt,
	)
	return i, err
}

const getSquadByWorkspaceAndName = `-- name: GetSquadByWorkspaceAndName :one
SELECT id, workspace_id, name, description, leader_id, creator_id, created_at, updated_at, archived_at, archived_by, avatar_url, instructions FROM squad
WHERE workspace_id = $1 AND name = $2
`

type GetSquadByWorkspaceAndNameParams struct {
	WorkspaceID pgtype.UUID `json:"workspace_id"`
	Name        string      `json:"name"`
}

func (q *Queries) GetSquadByWorkspaceAndName(ctx context.Context, arg GetSquadByWorkspaceAndNameParams) (Squad, error) {
	row := q.db.QueryRow(ctx, getSquadByWorkspaceAndName, arg.WorkspaceID, arg.Name)
	var i Squad
	err := row.Scan(
		&i.ID,
		&i.WorkspaceID,
		&i.Name,
		&i.Description,
		&i.LeaderID,
		&i.CreatorID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ArchivedAt,
		&i.ArchivedBy,
		&i.AvatarUrl,
		&i.Instructions,
	)
	return i, err
}

const listSkillFilesByWorkspace = `-- name: ListSkillFilesByWorkspace :many
SELECT sf.id, sf.skill_id, sf.path, sf.content, sf.created_at, sf.updated_at FROM skill_file sf
JOIN skill s ON s.id = sf.skill_id
WHERE s.workspace_id = $1
ORDER BY sf.skill_id, sf.path ASC
`

func (q *Queries) ListSkillFilesByWorkspace(ctx context.Context, workspaceID pgtype.UUID) ([]SkillFile, error) {
	rows, err := q.db.Query(ctx, listSkillFilesByWorkspace, workspaceID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []SkillFile{}
	for rows.Next() {
		var i SkillFile
		if err := rows.Scan(
			&i.ID,
			&i.SkillID,
			&i.Path,
			&i.Content,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
