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

package db

import (
	"context"
	"database/sql"
)

const allQcP1Attributes = `-- name: AllQcP1Attributes :many
SELECT qualityattribute_id,qtyremoved,crops.cropname,qtytaken,percentage,qualityattributes.description FROM qcp1_attributes
JOIN   qcp1 on qcp1.id = qcp1_attributes.qcp1_id
JOIN   receptionform on receptionform.id = qcp1.receptionform_id
JOIN   qualityattributes on qualityattributes.id  = qcp1_attributes.qualityattribute_id
JOIN   crops on crops.id = receptionform.crop_id
WHERE  qcp1_attributes.qcp1_id = $1
`

type AllQcP1AttributesRow struct {
	QualityattributeID int32   `json:"qualityattribute_id"`
	Qtyremoved         float64 `json:"qtyremoved"`
	Cropname           string  `json:"cropname"`
	Qtytaken           float64 `json:"qtytaken"`
	Percentage         float64 `json:"percentage"`
	Description        string  `json:"description"`
}

func (q *Queries) AllQcP1Attributes(ctx context.Context, qcp1ID int32) ([]AllQcP1AttributesRow, error) {
	rows, err := q.db.QueryContext(ctx, allQcP1Attributes, qcp1ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllQcP1AttributesRow{}
	for rows.Next() {
		var i AllQcP1AttributesRow
		if err := rows.Scan(
			&i.QualityattributeID,
			&i.Qtyremoved,
			&i.Cropname,
			&i.Qtytaken,
			&i.Percentage,
			&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 checkQcp1ID = `-- name: CheckQcp1ID :many
SELECT id, qcp1_id, qualityattribute_id, qtyremoved, qtytaken, other, percentage, traceabilitycode, created_at FROM qcp1_attributes
where qcp1_id = $1
`

func (q *Queries) CheckQcp1ID(ctx context.Context, qcp1ID int32) ([]Qcp1Attribute, error) {
	rows, err := q.db.QueryContext(ctx, checkQcp1ID, qcp1ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp1Attribute{}
	for rows.Next() {
		var i Qcp1Attribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp1ID,
			&i.QualityattributeID,
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.Other,
			&i.Percentage,
			&i.Traceabilitycode,
			&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 createQcp1Attributes = `-- name: CreateQcp1Attributes :one
INSERT INTO qcp1_attributes (
     qcp1_id ,             
     qualityattribute_id,
     qtyRemoved,
	   qtyTaken,
	   other,                
	   traceabilitycode,    
	 percentage           
 ) VALUES (
     $1, 
     $2, 
     $3,
     $4,
     $5, 
     $6,
     $7
    ) 
RETURNING id, qcp1_id, qualityattribute_id, qtyremoved, qtytaken, other, percentage, traceabilitycode, created_at
`

type CreateQcp1AttributesParams struct {
	Qcp1ID             int32          `json:"qcp1_id"`
	QualityattributeID int32          `json:"qualityattribute_id"`
	Qtyremoved         float64        `json:"qtyremoved"`
	Qtytaken           float64        `json:"qtytaken"`
	Other              sql.NullString `json:"other"`
	Traceabilitycode   string         `json:"traceabilitycode"`
	Percentage         float64        `json:"percentage"`
}

func (q *Queries) CreateQcp1Attributes(ctx context.Context, arg CreateQcp1AttributesParams) (Qcp1Attribute, error) {
	row := q.db.QueryRowContext(ctx, createQcp1Attributes,
		arg.Qcp1ID,
		arg.QualityattributeID,
		arg.Qtyremoved,
		arg.Qtytaken,
		arg.Other,
		arg.Traceabilitycode,
		arg.Percentage,
	)
	var i Qcp1Attribute
	err := row.Scan(
		&i.ID,
		&i.Qcp1ID,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Other,
		&i.Percentage,
		&i.Traceabilitycode,
		&i.CreatedAt,
	)
	return i, err
}

const deleteQcp1Attribute = `-- name: DeleteQcp1Attribute :exec
DELETE FROM qcp1_attributes WHERE  qcp1_id= $1
`

func (q *Queries) DeleteQcp1Attribute(ctx context.Context, qcp1ID int32) error {
	_, err := q.db.ExecContext(ctx, deleteQcp1Attribute, qcp1ID)
	return err
}

const listQcp1Attributes = `-- name: ListQcp1Attributes :many
SELECT id, qcp1_id, qualityattribute_id, qtyremoved, qtytaken, other, percentage, traceabilitycode, created_at FROM qcp1_attributes
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListQcp1Attributes(ctx context.Context, arg ListQcp1AttributesParams) ([]Qcp1Attribute, error) {
	rows, err := q.db.QueryContext(ctx, listQcp1Attributes, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp1Attribute{}
	for rows.Next() {
		var i Qcp1Attribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp1ID,
			&i.QualityattributeID,
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.Other,
			&i.Percentage,
			&i.Traceabilitycode,
			&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 updateQcp1Attribute = `-- name: UpdateQcp1Attribute :one
UPDATE qcp1_attributes
  set 
     qcp1_id = $2,               
     qualityattribute_id = $3,
     qtyRemoved = $4,
	 qtyTaken = $5,
	 other = $6,                
	 traceabilitycode = $7,    
	 percentage = $8     
WHERE id = $1
RETURNING id, qcp1_id, qualityattribute_id, qtyremoved, qtytaken, other, percentage, traceabilitycode, created_at
`

type UpdateQcp1AttributeParams struct {
	ID                 int64          `json:"id"`
	Qcp1ID             int32          `json:"qcp1_id"`
	QualityattributeID int32          `json:"qualityattribute_id"`
	Qtyremoved         float64        `json:"qtyremoved"`
	Qtytaken           float64        `json:"qtytaken"`
	Other              sql.NullString `json:"other"`
	Traceabilitycode   string         `json:"traceabilitycode"`
	Percentage         float64        `json:"percentage"`
}

func (q *Queries) UpdateQcp1Attribute(ctx context.Context, arg UpdateQcp1AttributeParams) (Qcp1Attribute, error) {
	row := q.db.QueryRowContext(ctx, updateQcp1Attribute,
		arg.ID,
		arg.Qcp1ID,
		arg.QualityattributeID,
		arg.Qtyremoved,
		arg.Qtytaken,
		arg.Other,
		arg.Traceabilitycode,
		arg.Percentage,
	)
	var i Qcp1Attribute
	err := row.Scan(
		&i.ID,
		&i.Qcp1ID,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Other,
		&i.Percentage,
		&i.Traceabilitycode,
		&i.CreatedAt,
	)
	return i, err
}
