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

package db

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

const createPlannedConsignmentTpDetails = `-- name: CreatePlannedConsignmentTpDetails :one
INSERT INTO plannedconsignments_tpdetails (
    plannedconsignments_id,
    country_id,              
    modesoftransport_id,
    exit_date,
    exitpoint_id,
    airline_id,
    exithandler_id
 ) VALUES (
    $1,
    $2,
    $3,
    $4,
    $5,
    $6,
    $7
) 
RETURNING id, plannedconsignments_id, country_id, modesoftransport_id, exit_date, exitpoint_id, airline_id, exithandler_id, created_at
`

type CreatePlannedConsignmentTpDetailsParams struct {
	PlannedconsignmentsID string        `json:"plannedconsignments_id"`
	CountryID             int32         `json:"country_id"`
	ModesoftransportID    int32         `json:"modesoftransport_id"`
	ExitDate              time.Time     `json:"exit_date"`
	ExitpointID           int32         `json:"exitpoint_id"`
	AirlineID             sql.NullInt32 `json:"airline_id"`
	ExithandlerID         sql.NullInt32 `json:"exithandler_id"`
}

func (q *Queries) CreatePlannedConsignmentTpDetails(ctx context.Context, arg CreatePlannedConsignmentTpDetailsParams) (PlannedconsignmentsTpdetail, error) {
	row := q.db.QueryRowContext(ctx, createPlannedConsignmentTpDetails,
		arg.PlannedconsignmentsID,
		arg.CountryID,
		arg.ModesoftransportID,
		arg.ExitDate,
		arg.ExitpointID,
		arg.AirlineID,
		arg.ExithandlerID,
	)
	var i PlannedconsignmentsTpdetail
	err := row.Scan(
		&i.ID,
		&i.PlannedconsignmentsID,
		&i.CountryID,
		&i.ModesoftransportID,
		&i.ExitDate,
		&i.ExitpointID,
		&i.AirlineID,
		&i.ExithandlerID,
		&i.CreatedAt,
	)
	return i, err
}

const deletePlannedConsigmentTpDetails = `-- name: DeletePlannedConsigmentTpDetails :exec
DELETE FROM plannedconsignments_tpdetails WHERE id= $1
`

func (q *Queries) DeletePlannedConsigmentTpDetails(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deletePlannedConsigmentTpDetails, id)
	return err
}

const getPlannedConsignmentNoTpDetails = `-- name: GetPlannedConsignmentNoTpDetails :one
SELECT id, plannedconsignments_id, country_id, modesoftransport_id, exit_date, exitpoint_id, airline_id, exithandler_id, created_at FROM plannedconsignments_tpdetails
WHERE plannedconsignments_id = $1 LIMIT 1
`

func (q *Queries) GetPlannedConsignmentNoTpDetails(ctx context.Context, plannedconsignmentsID string) (PlannedconsignmentsTpdetail, error) {
	row := q.db.QueryRowContext(ctx, getPlannedConsignmentNoTpDetails, plannedconsignmentsID)
	var i PlannedconsignmentsTpdetail
	err := row.Scan(
		&i.ID,
		&i.PlannedconsignmentsID,
		&i.CountryID,
		&i.ModesoftransportID,
		&i.ExitDate,
		&i.ExitpointID,
		&i.AirlineID,
		&i.ExithandlerID,
		&i.CreatedAt,
	)
	return i, err
}

const listPlannedConsigmentsTpDetails = `-- name: ListPlannedConsigmentsTpDetails :many
SELECT id, plannedconsignments_id, country_id, modesoftransport_id, exit_date, exitpoint_id, airline_id, exithandler_id, created_at FROM plannedconsignments_tpdetails
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListPlannedConsigmentsTpDetails(ctx context.Context, arg ListPlannedConsigmentsTpDetailsParams) ([]PlannedconsignmentsTpdetail, error) {
	rows, err := q.db.QueryContext(ctx, listPlannedConsigmentsTpDetails, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PlannedconsignmentsTpdetail{}
	for rows.Next() {
		var i PlannedconsignmentsTpdetail
		if err := rows.Scan(
			&i.ID,
			&i.PlannedconsignmentsID,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&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 updatePlannedConsigmentTpDetails = `-- name: UpdatePlannedConsigmentTpDetails :one
UPDATE plannedconsignments_tpdetails
  set 
    country_id = $2,              
    modesoftransport_id = $3,
    exit_date = $4,
    exitpoint_id = $5,
    airline_id = $6,
    exithandler_id = $7
WHERE id = $1
RETURNING id, plannedconsignments_id, country_id, modesoftransport_id, exit_date, exitpoint_id, airline_id, exithandler_id, created_at
`

type UpdatePlannedConsigmentTpDetailsParams struct {
	ID                 int64         `json:"id"`
	CountryID          int32         `json:"country_id"`
	ModesoftransportID int32         `json:"modesoftransport_id"`
	ExitDate           time.Time     `json:"exit_date"`
	ExitpointID        int32         `json:"exitpoint_id"`
	AirlineID          sql.NullInt32 `json:"airline_id"`
	ExithandlerID      sql.NullInt32 `json:"exithandler_id"`
}

func (q *Queries) UpdatePlannedConsigmentTpDetails(ctx context.Context, arg UpdatePlannedConsigmentTpDetailsParams) (PlannedconsignmentsTpdetail, error) {
	row := q.db.QueryRowContext(ctx, updatePlannedConsigmentTpDetails,
		arg.ID,
		arg.CountryID,
		arg.ModesoftransportID,
		arg.ExitDate,
		arg.ExitpointID,
		arg.AirlineID,
		arg.ExithandlerID,
	)
	var i PlannedconsignmentsTpdetail
	err := row.Scan(
		&i.ID,
		&i.PlannedconsignmentsID,
		&i.CountryID,
		&i.ModesoftransportID,
		&i.ExitDate,
		&i.ExitpointID,
		&i.AirlineID,
		&i.ExithandlerID,
		&i.CreatedAt,
	)
	return i, err
}
