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

package db

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

const checkQcp5InspectionReportByConsignment = `-- name: CheckQcp5InspectionReportByConsignment :one
 SELECT EXISTS(
      SELECT 1 FROM qcp5inspectionreportrecommendation
      WHERE consignment_no = $1
 )
`

func (q *Queries) CheckQcp5InspectionReportByConsignment(ctx context.Context, consignmentNo string) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkQcp5InspectionReportByConsignment, consignmentNo)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const createQcp5InspectionReportRecommendation = `-- name: CreateQcp5InspectionReportRecommendation :one
INSERT INTO qcp5inspectionreportrecommendation (
    consignment_no,
    consignment_status,
    target,
    documentdate,
    documentnumber,
    instructions,
    rejectionreason,
    rejectionweight,
    passedweight,
    user_id,
    exportcompany_id
 ) VALUES (
    $1, 
    $2, 
    $3, 
    $4, 
    $5,
    $6,
    $7,
    $8,
    $9,
    $10,
    $11
 ) RETURNING id, consignment_no, consignment_status, target, documentdate, documentnumber, instructions, rejectionreason, rejectionweight, passedweight, user_id, exportcompany_id, created_at
`

type CreateQcp5InspectionReportRecommendationParams struct {
	ConsignmentNo     string          `json:"consignment_no"`
	ConsignmentStatus string          `json:"consignment_status"`
	Target            sql.NullString  `json:"target"`
	Documentdate      sql.NullString  `json:"documentdate"`
	Documentnumber    sql.NullString  `json:"documentnumber"`
	Instructions      sql.NullString  `json:"instructions"`
	Rejectionreason   sql.NullString  `json:"rejectionreason"`
	Rejectionweight   sql.NullFloat64 `json:"rejectionweight"`
	Passedweight      sql.NullFloat64 `json:"passedweight"`
	UserID            int32           `json:"user_id"`
	ExportcompanyID   int32           `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp5InspectionReportRecommendation(ctx context.Context, arg CreateQcp5InspectionReportRecommendationParams) (Qcp5inspectionreportrecommendation, error) {
	row := q.db.QueryRowContext(ctx, createQcp5InspectionReportRecommendation,
		arg.ConsignmentNo,
		arg.ConsignmentStatus,
		arg.Target,
		arg.Documentdate,
		arg.Documentnumber,
		arg.Instructions,
		arg.Rejectionreason,
		arg.Rejectionweight,
		arg.Passedweight,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp5inspectionreportrecommendation
	err := row.Scan(
		&i.ID,
		&i.ConsignmentNo,
		&i.ConsignmentStatus,
		&i.Target,
		&i.Documentdate,
		&i.Documentnumber,
		&i.Instructions,
		&i.Rejectionreason,
		&i.Rejectionweight,
		&i.Passedweight,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp5InspectionReports = `-- name: CreateQcp5InspectionReports :one
INSERT INTO qcp5inspectionreport (
    consignment_no,
    notes,
    user_id,
    exportcompany_id
 ) VALUES (
    $1, 
    $2, 
    $3, 
    $4
 ) RETURNING id, consignment_no, notes, user_id, exportcompany_id, created_at
`

type CreateQcp5InspectionReportsParams struct {
	ConsignmentNo   string `json:"consignment_no"`
	Notes           string `json:"notes"`
	UserID          int32  `json:"user_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp5InspectionReports(ctx context.Context, arg CreateQcp5InspectionReportsParams) (Qcp5inspectionreport, error) {
	row := q.db.QueryRowContext(ctx, createQcp5InspectionReports,
		arg.ConsignmentNo,
		arg.Notes,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp5inspectionreport
	err := row.Scan(
		&i.ID,
		&i.ConsignmentNo,
		&i.Notes,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const getQcp5InspectionReportByConsignment = `-- name: GetQcp5InspectionReportByConsignment :one
SELECT qcp5inspectionreport.consignment_no,qcp5inspectionreport.notes,
qcp5inspectionreport.notes,qcp5inspectionreportrecommendation.consignment_status,qcp5inspectionreport.id,
qcp5inspectionreportrecommendation.instructions,qcp5inspectionreport.created_at,
users.fullname,users.signature,exportcompanies.expname,exportcompanies.logo,exportcompanies.id as exporter_id FROM qcp5inspectionreport
LEFT JOIN qcp5inspectionreportrecommendation on qcp5inspectionreportrecommendation.consignment_no = qcp5inspectionreport.consignment_no
JOIN  exportcompanies on exportcompanies.id = qcp5inspectionreport.exportcompany_id
JOIN  users           on users.id           = qcp5inspectionreport.user_id
WHERE qcp5inspectionreport.consignment_no = $1 
LIMIT 1
`

type GetQcp5InspectionReportByConsignmentRow struct {
	ConsignmentNo     string         `json:"consignment_no"`
	Notes             string         `json:"notes"`
	Notes_2           string         `json:"notes_2"`
	ConsignmentStatus sql.NullString `json:"consignment_status"`
	ID                int64          `json:"id"`
	Instructions      sql.NullString `json:"instructions"`
	CreatedAt         time.Time      `json:"created_at"`
	Fullname          string         `json:"fullname"`
	Signature         sql.NullString `json:"signature"`
	Expname           string         `json:"expname"`
	Logo              sql.NullString `json:"logo"`
	ExporterID        int64          `json:"exporter_id"`
}

func (q *Queries) GetQcp5InspectionReportByConsignment(ctx context.Context, consignmentNo string) (GetQcp5InspectionReportByConsignmentRow, error) {
	row := q.db.QueryRowContext(ctx, getQcp5InspectionReportByConsignment, consignmentNo)
	var i GetQcp5InspectionReportByConsignmentRow
	err := row.Scan(
		&i.ConsignmentNo,
		&i.Notes,
		&i.Notes_2,
		&i.ConsignmentStatus,
		&i.ID,
		&i.Instructions,
		&i.CreatedAt,
		&i.Fullname,
		&i.Signature,
		&i.Expname,
		&i.Logo,
		&i.ExporterID,
	)
	return i, err
}

const getQcp5InspectionReportDetailsByConsignment = `-- name: GetQcp5InspectionReportDetailsByConsignment :one
SELECT EXISTS (
    SELECT 1 FROM qcp5inspectionreport
    WHERE consignment_no = $1
)
`

func (q *Queries) GetQcp5InspectionReportDetailsByConsignment(ctx context.Context, consignmentNo string) (bool, error) {
	row := q.db.QueryRowContext(ctx, getQcp5InspectionReportDetailsByConsignment, consignmentNo)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const updateQcp5InspectionReport = `-- name: UpdateQcp5InspectionReport :one
 UPDATE qcp5inspectionreport
   set
    notes = $2
   WHERE id = $1
 RETURNING id, consignment_no, notes, user_id, exportcompany_id, created_at
`

type UpdateQcp5InspectionReportParams struct {
	ID    int64  `json:"id"`
	Notes string `json:"notes"`
}

func (q *Queries) UpdateQcp5InspectionReport(ctx context.Context, arg UpdateQcp5InspectionReportParams) (Qcp5inspectionreport, error) {
	row := q.db.QueryRowContext(ctx, updateQcp5InspectionReport, arg.ID, arg.Notes)
	var i Qcp5inspectionreport
	err := row.Scan(
		&i.ID,
		&i.ConsignmentNo,
		&i.Notes,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}
