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

package db

import (
	"context"
	"time"

	"github.com/google/uuid"
)

const allZones = `-- name: AllZones :many
SELECT zones.zone,zones.created_at,zones.id FROM zones
`

type AllZonesRow struct {
	Zone      string    `json:"zone"`
	CreatedAt time.Time `json:"created_at"`
	ID        int64     `json:"id"`
}

func (q *Queries) AllZones(ctx context.Context) ([]AllZonesRow, error) {
	rows, err := q.db.QueryContext(ctx, allZones)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllZonesRow{}
	for rows.Next() {
		var i AllZonesRow
		if err := rows.Scan(&i.Zone, &i.CreatedAt, &i.ID); 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 allZonesForDistrict = `-- name: AllZonesForDistrict :many
SELECT zones.zone,zone_district.zone_id,zone_district.district_id,zone_district.created_at FROM zone_district
JOIN  zones on zones.id = zone_district.zone_id
WHERE zone_district.district_id = $1
`

type AllZonesForDistrictRow struct {
	Zone       string    `json:"zone"`
	ZoneID     int32     `json:"zone_id"`
	DistrictID int32     `json:"district_id"`
	CreatedAt  time.Time `json:"created_at"`
}

func (q *Queries) AllZonesForDistrict(ctx context.Context, districtID int32) ([]AllZonesForDistrictRow, error) {
	rows, err := q.db.QueryContext(ctx, allZonesForDistrict, districtID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllZonesForDistrictRow{}
	for rows.Next() {
		var i AllZonesForDistrictRow
		if err := rows.Scan(
			&i.Zone,
			&i.ZoneID,
			&i.DistrictID,
			&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 createDistrictZone = `-- name: CreateDistrictZone :one
 INSERT INTO zone_district (
    id,
    district_id,
    zone_id
 ) VALUES (
    $1,$2,$3
 ) RETURNING id, zone_id, district_id, created_at
`

type CreateDistrictZoneParams struct {
	ID         uuid.UUID `json:"id"`
	DistrictID int32     `json:"district_id"`
	ZoneID     int32     `json:"zone_id"`
}

func (q *Queries) CreateDistrictZone(ctx context.Context, arg CreateDistrictZoneParams) (ZoneDistrict, error) {
	row := q.db.QueryRowContext(ctx, createDistrictZone, arg.ID, arg.DistrictID, arg.ZoneID)
	var i ZoneDistrict
	err := row.Scan(
		&i.ID,
		&i.ZoneID,
		&i.DistrictID,
		&i.CreatedAt,
	)
	return i, err
}

const createZone = `-- name: CreateZone :one
INSERT INTO zones (
    zone
 ) VALUES (
    $1
 ) RETURNING id, zone, created_at
`

func (q *Queries) CreateZone(ctx context.Context, zone string) (Zone, error) {
	row := q.db.QueryRowContext(ctx, createZone, zone)
	var i Zone
	err := row.Scan(&i.ID, &i.Zone, &i.CreatedAt)
	return i, err
}

const deleteZone = `-- name: DeleteZone :exec
DELETE FROM zones WHERE id= $1
`

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

const getZone = `-- name: GetZone :one
SELECT id, zone, created_at FROM zones
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetZone(ctx context.Context, id int64) (Zone, error) {
	row := q.db.QueryRowContext(ctx, getZone, id)
	var i Zone
	err := row.Scan(&i.ID, &i.Zone, &i.CreatedAt)
	return i, err
}

const getZoneByName = `-- name: GetZoneByName :one
SELECT id, zone, created_at FROM zones WHERE zone= $1
`

func (q *Queries) GetZoneByName(ctx context.Context, zone string) (Zone, error) {
	row := q.db.QueryRowContext(ctx, getZoneByName, zone)
	var i Zone
	err := row.Scan(&i.ID, &i.Zone, &i.CreatedAt)
	return i, err
}

const getZoneID = `-- name: GetZoneID :one
SELECT zones.id FROM zones
WHERE zone = $1 LIMIT 1
`

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

const listZones = `-- name: ListZones :many
SELECT id, zone, created_at from zones
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListZones(ctx context.Context, arg ListZonesParams) ([]Zone, error) {
	rows, err := q.db.QueryContext(ctx, listZones, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Zone{}
	for rows.Next() {
		var i Zone
		if err := rows.Scan(&i.ID, &i.Zone, &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 updateZone = `-- name: UpdateZone :one
UPDATE zones
  set 
    zone = $2
WHERE id = $1
RETURNING id, zone, created_at
`

type UpdateZoneParams struct {
	ID   int64  `json:"id"`
	Zone string `json:"zone"`
}

func (q *Queries) UpdateZone(ctx context.Context, arg UpdateZoneParams) (Zone, error) {
	row := q.db.QueryRowContext(ctx, updateZone, arg.ID, arg.Zone)
	var i Zone
	err := row.Scan(&i.ID, &i.Zone, &i.CreatedAt)
	return i, err
}
