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

package db

import (
	"context"
	"time"
)

const allExitPoints = `-- name: AllExitPoints :many
SELECT expcode,exitpoints.id,expdescription,village_id,parish_id,district_id,expwhatsapp
motdescription,modeoftransport_id mot_id, exitpoints.created_at created_at FROM exitpoints
JOIN modesoftransport on modesoftransport.id = exitpoints.modeoftransport_id
LIMIT $1
OFFSET $2
`

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

type AllExitPointsRow struct {
	Expcode        string    `json:"expcode"`
	ID             int64     `json:"id"`
	Expdescription string    `json:"expdescription"`
	VillageID      int32     `json:"village_id"`
	ParishID       int32     `json:"parish_id"`
	DistrictID     int32     `json:"district_id"`
	Motdescription string    `json:"motdescription"`
	MotID          int32     `json:"mot_id"`
	CreatedAt      time.Time `json:"created_at"`
}

func (q *Queries) AllExitPoints(ctx context.Context, arg AllExitPointsParams) ([]AllExitPointsRow, error) {
	rows, err := q.db.QueryContext(ctx, allExitPoints, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllExitPointsRow{}
	for rows.Next() {
		var i AllExitPointsRow
		if err := rows.Scan(
			&i.Expcode,
			&i.ID,
			&i.Expdescription,
			&i.VillageID,
			&i.ParishID,
			&i.DistrictID,
			&i.Motdescription,
			&i.MotID,
			&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 createExitPoint = `-- name: CreateExitPoint :one
INSERT INTO exitpoints (
    expcode,     
    modeoftransport_id,                             
    expdescription,
    village_id,
    parish_id,
    district_id,
    longtitude,
    latitude,
    expwhatsapp
 ) VALUES (
    $1, 
    $2, 
    $3, 
    $4, 
    $5, 
    $6, 
    $7,
    $8,
    $9
 ) RETURNING id, expcode, modeoftransport_id, expdescription, village_id, parish_id, district_id, expwhatsapp, longtitude, latitude, status, created_at
`

type CreateExitPointParams struct {
	Expcode           string  `json:"expcode"`
	ModeoftransportID int32   `json:"modeoftransport_id"`
	Expdescription    string  `json:"expdescription"`
	VillageID         int32   `json:"village_id"`
	ParishID          int32   `json:"parish_id"`
	DistrictID        int32   `json:"district_id"`
	Longtitude        float64 `json:"longtitude"`
	Latitude          float64 `json:"latitude"`
	Expwhatsapp       string  `json:"expwhatsapp"`
}

func (q *Queries) CreateExitPoint(ctx context.Context, arg CreateExitPointParams) (Exitpoint, error) {
	row := q.db.QueryRowContext(ctx, createExitPoint,
		arg.Expcode,
		arg.ModeoftransportID,
		arg.Expdescription,
		arg.VillageID,
		arg.ParishID,
		arg.DistrictID,
		arg.Longtitude,
		arg.Latitude,
		arg.Expwhatsapp,
	)
	var i Exitpoint
	err := row.Scan(
		&i.ID,
		&i.Expcode,
		&i.ModeoftransportID,
		&i.Expdescription,
		&i.VillageID,
		&i.ParishID,
		&i.DistrictID,
		&i.Expwhatsapp,
		&i.Longtitude,
		&i.Latitude,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const deleteExitPoint = `-- name: DeleteExitPoint :exec
DELETE FROM exitpoints WHERE id= $1
`

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

const getExitPoint = `-- name: GetExitPoint :one
SELECT id, expcode, modeoftransport_id, expdescription, village_id, parish_id, district_id, expwhatsapp, longtitude, latitude, status, created_at FROM exitpoints
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetExitPoint(ctx context.Context, id int64) (Exitpoint, error) {
	row := q.db.QueryRowContext(ctx, getExitPoint, id)
	var i Exitpoint
	err := row.Scan(
		&i.ID,
		&i.Expcode,
		&i.ModeoftransportID,
		&i.Expdescription,
		&i.VillageID,
		&i.ParishID,
		&i.DistrictID,
		&i.Expwhatsapp,
		&i.Longtitude,
		&i.Latitude,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const getExitPointIDByCode = `-- name: GetExitPointIDByCode :one
SELECT id FROM exitpoints
WHERE  expcode = $1 LIMIT 1
`

func (q *Queries) GetExitPointIDByCode(ctx context.Context, expcode string) (int64, error) {
	row := q.db.QueryRowContext(ctx, getExitPointIDByCode, expcode)
	var id int64
	err := row.Scan(&id)
	return id, err
}

const getExitPointIDByName = `-- name: GetExitPointIDByName :one
SELECT id FROM exitpoints
WHERE  expdescription = $1 LIMIT 1
`

func (q *Queries) GetExitPointIDByName(ctx context.Context, expdescription string) (int64, error) {
	row := q.db.QueryRowContext(ctx, getExitPointIDByName, expdescription)
	var id int64
	err := row.Scan(&id)
	return id, err
}

const listAllExitPointIDs = `-- name: ListAllExitPointIDs :many
SELECT id from exitpoints
`

func (q *Queries) ListAllExitPointIDs(ctx context.Context) ([]int64, error) {
	rows, err := q.db.QueryContext(ctx, listAllExitPointIDs)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []int64{}
	for rows.Next() {
		var id int64
		if err := rows.Scan(&id); err != nil {
			return nil, err
		}
		items = append(items, id)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const listAllExitPoints = `-- name: ListAllExitPoints :many
SELECT expcode,exitpoints.id,expdescription,village,parish,districts.name,expwhatsapp,
motdescription,modeoftransport_id mot_id, exitpoints.created_at created_at FROM exitpoints
JOIN modesoftransport on modesoftransport.id = exitpoints.modeoftransport_id
JOIN villages  on villages.id  = exitpoints.village_id
JOIN parishes  on parishes.id  = exitpoints.parish_id
JOIN districts on districts.id = exitpoints.district_id
`

type ListAllExitPointsRow struct {
	Expcode        string    `json:"expcode"`
	ID             int64     `json:"id"`
	Expdescription string    `json:"expdescription"`
	Village        string    `json:"village"`
	Parish         string    `json:"parish"`
	Name           string    `json:"name"`
	Expwhatsapp    string    `json:"expwhatsapp"`
	Motdescription string    `json:"motdescription"`
	MotID          int32     `json:"mot_id"`
	CreatedAt      time.Time `json:"created_at"`
}

func (q *Queries) ListAllExitPoints(ctx context.Context) ([]ListAllExitPointsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllExitPoints)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllExitPointsRow{}
	for rows.Next() {
		var i ListAllExitPointsRow
		if err := rows.Scan(
			&i.Expcode,
			&i.ID,
			&i.Expdescription,
			&i.Village,
			&i.Parish,
			&i.Name,
			&i.Expwhatsapp,
			&i.Motdescription,
			&i.MotID,
			&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 listExitPoints = `-- name: ListExitPoints :many
SELECT id, expcode, modeoftransport_id, expdescription, village_id, parish_id, district_id, expwhatsapp, longtitude, latitude, status, created_at FROM exitpoints
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListExitPoints(ctx context.Context, arg ListExitPointsParams) ([]Exitpoint, error) {
	rows, err := q.db.QueryContext(ctx, listExitPoints, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Exitpoint{}
	for rows.Next() {
		var i Exitpoint
		if err := rows.Scan(
			&i.ID,
			&i.Expcode,
			&i.ModeoftransportID,
			&i.Expdescription,
			&i.VillageID,
			&i.ParishID,
			&i.DistrictID,
			&i.Expwhatsapp,
			&i.Longtitude,
			&i.Latitude,
			&i.Status,
			&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 updateExitPoint = `-- name: UpdateExitPoint :one
UPDATE exitpoints
  set 
    expcode = $2,     
    modeoftransport_id = $3,                             
    expdescription = $4,
    village_id = $5,
    parish_id  = $6,
    district_id = $7,
    expwhatsapp = $8
WHERE id = $1
RETURNING id, expcode, modeoftransport_id, expdescription, village_id, parish_id, district_id, expwhatsapp, longtitude, latitude, status, created_at
`

type UpdateExitPointParams struct {
	ID                int64  `json:"id"`
	Expcode           string `json:"expcode"`
	ModeoftransportID int32  `json:"modeoftransport_id"`
	Expdescription    string `json:"expdescription"`
	VillageID         int32  `json:"village_id"`
	ParishID          int32  `json:"parish_id"`
	DistrictID        int32  `json:"district_id"`
	Expwhatsapp       string `json:"expwhatsapp"`
}

func (q *Queries) UpdateExitPoint(ctx context.Context, arg UpdateExitPointParams) (Exitpoint, error) {
	row := q.db.QueryRowContext(ctx, updateExitPoint,
		arg.ID,
		arg.Expcode,
		arg.ModeoftransportID,
		arg.Expdescription,
		arg.VillageID,
		arg.ParishID,
		arg.DistrictID,
		arg.Expwhatsapp,
	)
	var i Exitpoint
	err := row.Scan(
		&i.ID,
		&i.Expcode,
		&i.ModeoftransportID,
		&i.Expdescription,
		&i.VillageID,
		&i.ParishID,
		&i.DistrictID,
		&i.Expwhatsapp,
		&i.Longtitude,
		&i.Latitude,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const updateExitPointGps = `-- name: UpdateExitPointGps :one
UPDATE exitpoints
     SET 
       latitude = $2,
       longtitude = $3
WHERE id = $1
RETURNING id, expcode, modeoftransport_id, expdescription, village_id, parish_id, district_id, expwhatsapp, longtitude, latitude, status, created_at
`

type UpdateExitPointGpsParams struct {
	ID         int64   `json:"id"`
	Latitude   float64 `json:"latitude"`
	Longtitude float64 `json:"longtitude"`
}

func (q *Queries) UpdateExitPointGps(ctx context.Context, arg UpdateExitPointGpsParams) (Exitpoint, error) {
	row := q.db.QueryRowContext(ctx, updateExitPointGps, arg.ID, arg.Latitude, arg.Longtitude)
	var i Exitpoint
	err := row.Scan(
		&i.ID,
		&i.Expcode,
		&i.ModeoftransportID,
		&i.Expdescription,
		&i.VillageID,
		&i.ParishID,
		&i.DistrictID,
		&i.Expwhatsapp,
		&i.Longtitude,
		&i.Latitude,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}
