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

package db

import (
	"context"
	"database/sql"
	"time"

	"github.com/google/uuid"
)

const blockSession = `-- name: BlockSession :exec
UPDATE sessions
  set
  is_blocked = true
WHERE id = $1
`

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

const createSession = `-- name: CreateSession :one
INSERT INTO sessions (
    id,
    user_id,
    refresh_token,
    user_agent,
    client_ip,
    is_blocked,
    expires_at
 ) VALUES (
    $1, $2, $3, $4, $5, $6, $7
 ) RETURNING id, user_id, refresh_token, user_agent, client_ip, is_blocked, expires_at, exportcompany_id, packhouse_id, exitpoint_id, created_at
`

type CreateSessionParams struct {
	ID           uuid.UUID `json:"id"`
	UserID       int32     `json:"user_id"`
	RefreshToken string    `json:"refresh_token"`
	UserAgent    string    `json:"user_agent"`
	ClientIp     string    `json:"client_ip"`
	IsBlocked    bool      `json:"is_blocked"`
	ExpiresAt    time.Time `json:"expires_at"`
}

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) {
	row := q.db.QueryRowContext(ctx, createSession,
		arg.ID,
		arg.UserID,
		arg.RefreshToken,
		arg.UserAgent,
		arg.ClientIp,
		arg.IsBlocked,
		arg.ExpiresAt,
	)
	var i Session
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.RefreshToken,
		&i.UserAgent,
		&i.ClientIp,
		&i.IsBlocked,
		&i.ExpiresAt,
		&i.ExportcompanyID,
		&i.PackhouseID,
		&i.ExitpointID,
		&i.CreatedAt,
	)
	return i, err
}

const getSession = `-- name: GetSession :one
SELECT id, user_id, refresh_token, user_agent, client_ip, is_blocked, expires_at, exportcompany_id, packhouse_id, exitpoint_id, created_at FROM sessions
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetSession(ctx context.Context, id uuid.UUID) (Session, error) {
	row := q.db.QueryRowContext(ctx, getSession, id)
	var i Session
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.RefreshToken,
		&i.UserAgent,
		&i.ClientIp,
		&i.IsBlocked,
		&i.ExpiresAt,
		&i.ExportcompanyID,
		&i.PackhouseID,
		&i.ExitpointID,
		&i.CreatedAt,
	)
	return i, err
}

const getSessionUserID = `-- name: GetSessionUserID :one
SELECT id, user_id, refresh_token, user_agent, client_ip, is_blocked, expires_at, exportcompany_id, packhouse_id, exitpoint_id, created_at FROM sessions
WHERE user_id = $1 LIMIT 1
`

func (q *Queries) GetSessionUserID(ctx context.Context, userID int32) (Session, error) {
	row := q.db.QueryRowContext(ctx, getSessionUserID, userID)
	var i Session
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.RefreshToken,
		&i.UserAgent,
		&i.ClientIp,
		&i.IsBlocked,
		&i.ExpiresAt,
		&i.ExportcompanyID,
		&i.PackhouseID,
		&i.ExitpointID,
		&i.CreatedAt,
	)
	return i, err
}

const updateUserSession = `-- name: UpdateUserSession :exec
UPDATE sessions
  set
  packhouse_id  = $2,
  exportcompany_id = $3
WHERE id = $1
`

type UpdateUserSessionParams struct {
	ID              uuid.UUID     `json:"id"`
	PackhouseID     sql.NullInt32 `json:"packhouse_id"`
	ExportcompanyID sql.NullInt32 `json:"exportcompany_id"`
}

func (q *Queries) UpdateUserSession(ctx context.Context, arg UpdateUserSessionParams) error {
	_, err := q.db.ExecContext(ctx, updateUserSession, arg.ID, arg.PackhouseID, arg.ExportcompanyID)
	return err
}

const updateUserSessionExitPoint = `-- name: UpdateUserSessionExitPoint :exec
UPDATE sessions
  set
  exitpoint_id  = $2
WHERE id = $1
`

type UpdateUserSessionExitPointParams struct {
	ID          uuid.UUID     `json:"id"`
	ExitpointID sql.NullInt32 `json:"exitpoint_id"`
}

func (q *Queries) UpdateUserSessionExitPoint(ctx context.Context, arg UpdateUserSessionExitPointParams) error {
	_, err := q.db.ExecContext(ctx, updateUserSessionExitPoint, arg.ID, arg.ExitpointID)
	return err
}
