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

package db

import (
	"context"
	"database/sql"
)

const allQcP2Attributes = `-- name: AllQcP2Attributes :many
SELECT qualityattribute_id,qtyremoved qty_removed,
crops.cropname,qtytaken qty_taken,other,qcp2.batchno,qcp2.id,
receptionform.traceability_code,qualityattributes.description FROM qcp2_attributes
LEFT JOIN  qcp2 on qcp2.id = qcp2_attributes.qcp2_id
LEFT JOIN  receptionform on receptionform.id = qcp2.reception_id
LEFT JOIN  qualityattributes on qualityattributes.id  = qcp2_attributes.qualityattribute_id
LEFT JOIN  crops on crops.id = receptionform.crop_id
WHERE qcp2_attributes.qcp2_id = $1
`

type AllQcP2AttributesRow struct {
	QualityattributeID int32          `json:"qualityattribute_id"`
	QtyRemoved         float64        `json:"qty_removed"`
	Cropname           sql.NullString `json:"cropname"`
	QtyTaken           float64        `json:"qty_taken"`
	Other              sql.NullString `json:"other"`
	Batchno            sql.NullString `json:"batchno"`
	ID                 sql.NullInt64  `json:"id"`
	TraceabilityCode   sql.NullString `json:"traceability_code"`
	Description        sql.NullString `json:"description"`
}

func (q *Queries) AllQcP2Attributes(ctx context.Context, qcp2ID int32) ([]AllQcP2AttributesRow, error) {
	rows, err := q.db.QueryContext(ctx, allQcP2Attributes, qcp2ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllQcP2AttributesRow{}
	for rows.Next() {
		var i AllQcP2AttributesRow
		if err := rows.Scan(
			&i.QualityattributeID,
			&i.QtyRemoved,
			&i.Cropname,
			&i.QtyTaken,
			&i.Other,
			&i.Batchno,
			&i.ID,
			&i.TraceabilityCode,
			&i.Description,
		); 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 checkQcp2ID = `-- name: CheckQcp2ID :many
SELECT id, qcp2_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at FROM qcp2_attributes
where qcp2_id = $1
`

func (q *Queries) CheckQcp2ID(ctx context.Context, qcp2ID int32) ([]Qcp2Attribute, error) {
	rows, err := q.db.QueryContext(ctx, checkQcp2ID, qcp2ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp2Attribute{}
	for rows.Next() {
		var i Qcp2Attribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp2ID,
			&i.QualityattributeID,
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.Percentage,
			&i.Other,
			&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 createQcp2Attributes = `-- name: CreateQcp2Attributes :one
INSERT INTO qcp2_attributes (
     qcp2_id,
     qualityattribute_id,
     percentage,
     qtyremoved,
     qtytaken,
     other
 ) VALUES (
     $1, 
     $2, 
     $3,
     $4,
     $5,
     $6
    ) 
RETURNING id, qcp2_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at
`

type CreateQcp2AttributesParams struct {
	Qcp2ID             int32          `json:"qcp2_id"`
	QualityattributeID int32          `json:"qualityattribute_id"`
	Percentage         float64        `json:"percentage"`
	Qtyremoved         float64        `json:"qtyremoved"`
	Qtytaken           float64        `json:"qtytaken"`
	Other              sql.NullString `json:"other"`
}

func (q *Queries) CreateQcp2Attributes(ctx context.Context, arg CreateQcp2AttributesParams) (Qcp2Attribute, error) {
	row := q.db.QueryRowContext(ctx, createQcp2Attributes,
		arg.Qcp2ID,
		arg.QualityattributeID,
		arg.Percentage,
		arg.Qtyremoved,
		arg.Qtytaken,
		arg.Other,
	)
	var i Qcp2Attribute
	err := row.Scan(
		&i.ID,
		&i.Qcp2ID,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Percentage,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const deleteQcp2Attributes = `-- name: DeleteQcp2Attributes :exec
DELETE FROM qcp2_attributes WHERE qcp2_id= $1
`

func (q *Queries) DeleteQcp2Attributes(ctx context.Context, qcp2ID int32) error {
	_, err := q.db.ExecContext(ctx, deleteQcp2Attributes, qcp2ID)
	return err
}

const listQcp2Attributes = `-- name: ListQcp2Attributes :many
SELECT id, qcp2_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at FROM qcp2_attributes
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListQcp2Attributes(ctx context.Context, arg ListQcp2AttributesParams) ([]Qcp2Attribute, error) {
	rows, err := q.db.QueryContext(ctx, listQcp2Attributes, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp2Attribute{}
	for rows.Next() {
		var i Qcp2Attribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp2ID,
			&i.QualityattributeID,
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.Percentage,
			&i.Other,
			&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 updateQcp2Attributes = `-- name: UpdateQcp2Attributes :one
UPDATE qcp2_attributes
  set 
     qcp2_id = $2,
     qualityattribute_id  = $3,
     percentage = $4,
     qtyremoved = $5,
     qtytaken  = $6,
     other = $7
WHERE id = $1
RETURNING id, qcp2_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at
`

type UpdateQcp2AttributesParams struct {
	ID                 int64          `json:"id"`
	Qcp2ID             int32          `json:"qcp2_id"`
	QualityattributeID int32          `json:"qualityattribute_id"`
	Percentage         float64        `json:"percentage"`
	Qtyremoved         float64        `json:"qtyremoved"`
	Qtytaken           float64        `json:"qtytaken"`
	Other              sql.NullString `json:"other"`
}

func (q *Queries) UpdateQcp2Attributes(ctx context.Context, arg UpdateQcp2AttributesParams) (Qcp2Attribute, error) {
	row := q.db.QueryRowContext(ctx, updateQcp2Attributes,
		arg.ID,
		arg.Qcp2ID,
		arg.QualityattributeID,
		arg.Percentage,
		arg.Qtyremoved,
		arg.Qtytaken,
		arg.Other,
	)
	var i Qcp2Attribute
	err := row.Scan(
		&i.ID,
		&i.Qcp2ID,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Percentage,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}
