-- name: CreateZone :one
INSERT INTO zones (
    zone
 ) VALUES (
    $1
 ) RETURNING *;

-- name: CreateDistrictZone :one
 INSERT INTO zone_district (
    id,
    district_id,
    zone_id
 ) VALUES (
    $1,$2,$3
 ) RETURNING *;

-- name: GetZone :one
SELECT * FROM zones
WHERE id = $1 LIMIT 1;

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

-- name: ListZones :many
SELECT * from zones
ORDER BY id LIMIT $1
OFFSET $2;

-- name: AllZones :many
SELECT zones.zone,zones.created_at,zones.id FROM zones;

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

-- name: UpdateZone :one
UPDATE zones
  set 
    zone = $2
WHERE id = $1
RETURNING *;

-- name: DeleteZone :exec
DELETE FROM zones WHERE id= $1;


-- name: GetZoneByName :one
SELECT * FROM zones WHERE zone= $1;