-- 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 *;

 -- name: GetQcp1Attribute :one
SELECT * FROM qcp1_attributes
WHERE id = $1 LIMIT 1;

-- name: ListQcp1Attributes :many
SELECT * FROM qcp1_attributes
ORDER BY id LIMIT $1
OFFSET $2;

-- 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 *;

-- name: DeleteQcp1Attribute :exec
DELETE FROM qcp1_attributes WHERE  qcp1_id= $1;

-- 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;

-- name: CheckQcp1ID :many
SELECT * FROM qcp1_attributes
where qcp1_id = $1;
