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

package db

import (
	"context"
	"time"
)

const checkIDExistanceInRoaster = `-- name: CheckIDExistanceInRoaster :one
SELECT EXISTS(
   SELECT 1 FROM roastercount
   WHERE  user_id = $1
)
`

func (q *Queries) CheckIDExistanceInRoaster(ctx context.Context, userID int32) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkIDExistanceInRoaster, userID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const createExitPointRoaster = `-- name: CreateExitPointRoaster :one
INSERT INTO exitpointroaster (
     status,
     user_id,
     date,
     exitpoint_id,
     dayshift,    
     nightshift
 ) VALUES (
    $1, 
    $2,
    $3,
    $4,
    $5,
    $6
 ) RETURNING id, status, user_id, exitpoint_id, dayshift, nightshift, date, created_at
`

type CreateExitPointRoasterParams struct {
	Status      string    `json:"status"`
	UserID      int32     `json:"user_id"`
	Date        time.Time `json:"date"`
	ExitpointID int32     `json:"exitpoint_id"`
	Dayshift    bool      `json:"dayshift"`
	Nightshift  bool      `json:"nightshift"`
}

func (q *Queries) CreateExitPointRoaster(ctx context.Context, arg CreateExitPointRoasterParams) (Exitpointroaster, error) {
	row := q.db.QueryRowContext(ctx, createExitPointRoaster,
		arg.Status,
		arg.UserID,
		arg.Date,
		arg.ExitpointID,
		arg.Dayshift,
		arg.Nightshift,
	)
	var i Exitpointroaster
	err := row.Scan(
		&i.ID,
		&i.Status,
		&i.UserID,
		&i.ExitpointID,
		&i.Dayshift,
		&i.Nightshift,
		&i.Date,
		&i.CreatedAt,
	)
	return i, err
}

const createRoasterCount = `-- name: CreateRoasterCount :one
INSERT INTO roastercount (
     user_id,
     counter
 ) VALUES (
    $1, 
    $2
 ) RETURNING id, user_id, counter, created_at, updated_at
`

type CreateRoasterCountParams struct {
	UserID  int32 `json:"user_id"`
	Counter int32 `json:"counter"`
}

func (q *Queries) CreateRoasterCount(ctx context.Context, arg CreateRoasterCountParams) (Roastercount, error) {
	row := q.db.QueryRowContext(ctx, createRoasterCount, arg.UserID, arg.Counter)
	var i Roastercount
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Counter,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const roasterExitPointID = `-- name: RoasterExitPointID :one
SELECT exitpoint_id
FROM exitpointroaster
WHERE date  = $1 
AND user_id = $2
LIMIT 1
`

type RoasterExitPointIDParams struct {
	Date   time.Time `json:"date"`
	UserID int32     `json:"user_id"`
}

func (q *Queries) RoasterExitPointID(ctx context.Context, arg RoasterExitPointIDParams) (int32, error) {
	row := q.db.QueryRowContext(ctx, roasterExitPointID, arg.Date, arg.UserID)
	var exitpoint_id int32
	err := row.Scan(&exitpoint_id)
	return exitpoint_id, err
}

const roasterExitPointWeek = `-- name: RoasterExitPointWeek :many
SELECT exitpointroaster.status,exitpointroaster.user_id,
exitpointroaster.date,exitpointroaster.exitpoint_id,exitpoints.expdescription,
exitpoints.expcode,users.fullname,exitpointroaster.dayshift,exitpointroaster.nightshift 
FROM exitpointroaster
JOIN users on users.id = exitpointroaster.user_id
JOIN exitpoints on exitpoints.id = exitpointroaster.exitpoint_id
`

type RoasterExitPointWeekRow struct {
	Status         string    `json:"status"`
	UserID         int32     `json:"user_id"`
	Date           time.Time `json:"date"`
	ExitpointID    int32     `json:"exitpoint_id"`
	Expdescription string    `json:"expdescription"`
	Expcode        string    `json:"expcode"`
	Fullname       string    `json:"fullname"`
	Dayshift       bool      `json:"dayshift"`
	Nightshift     bool      `json:"nightshift"`
}

func (q *Queries) RoasterExitPointWeek(ctx context.Context) ([]RoasterExitPointWeekRow, error) {
	rows, err := q.db.QueryContext(ctx, roasterExitPointWeek)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []RoasterExitPointWeekRow{}
	for rows.Next() {
		var i RoasterExitPointWeekRow
		if err := rows.Scan(
			&i.Status,
			&i.UserID,
			&i.Date,
			&i.ExitpointID,
			&i.Expdescription,
			&i.Expcode,
			&i.Fullname,
			&i.Dayshift,
			&i.Nightshift,
		); 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 updateRoasterCount = `-- name: UpdateRoasterCount :one
UPDATE roastercount 
    SET
      counter = counter + 1
WHERE user_id = $1
RETURNING id, user_id, counter, created_at, updated_at
`

func (q *Queries) UpdateRoasterCount(ctx context.Context, userID int32) (Roastercount, error) {
	row := q.db.QueryRowContext(ctx, updateRoasterCount, userID)
	var i Roastercount
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Counter,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
