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

package db

import (
	"context"
	"time"
)

const allAirlines = `-- name: AllAirlines :many
SELECT airlines.id as airline_id,airlines.airlinecode,airlines.airlinename,modeoftransport_id mot_id,
motdescription,airlines.created_at created_at FROM airlines
JOIN modesoftransport on modesoftransport.id = airlines.modeoftransport_id
`

type AllAirlinesRow struct {
	AirlineID      int64     `json:"airline_id"`
	Airlinecode    string    `json:"airlinecode"`
	Airlinename    string    `json:"airlinename"`
	MotID          int32     `json:"mot_id"`
	Motdescription string    `json:"motdescription"`
	CreatedAt      time.Time `json:"created_at"`
}

func (q *Queries) AllAirlines(ctx context.Context) ([]AllAirlinesRow, error) {
	rows, err := q.db.QueryContext(ctx, allAirlines)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllAirlinesRow{}
	for rows.Next() {
		var i AllAirlinesRow
		if err := rows.Scan(
			&i.AirlineID,
			&i.Airlinecode,
			&i.Airlinename,
			&i.MotID,
			&i.Motdescription,
			&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 allListedAirlines = `-- name: AllListedAirlines :many
SELECT airlinecode,airlinename,airlines.id,modeoftransport_id mot_id,motdescription,airlines.created_at created_at FROM airlines
JOIN modesoftransport on modesoftransport.id = airlines.modeoftransport_id
`

type AllListedAirlinesRow struct {
	Airlinecode    string    `json:"airlinecode"`
	Airlinename    string    `json:"airlinename"`
	ID             int64     `json:"id"`
	MotID          int32     `json:"mot_id"`
	Motdescription string    `json:"motdescription"`
	CreatedAt      time.Time `json:"created_at"`
}

func (q *Queries) AllListedAirlines(ctx context.Context) ([]AllListedAirlinesRow, error) {
	rows, err := q.db.QueryContext(ctx, allListedAirlines)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllListedAirlinesRow{}
	for rows.Next() {
		var i AllListedAirlinesRow
		if err := rows.Scan(
			&i.Airlinecode,
			&i.Airlinename,
			&i.ID,
			&i.MotID,
			&i.Motdescription,
			&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 createAirline = `-- name: CreateAirline :one
INSERT INTO airlines (
    airlinecode,
    airlinename,
    modeoftransport_id
 ) VALUES (
    $1, $2, $3
 ) RETURNING id, airlinecode, airlinename, modeoftransport_id, status, created_at
`

type CreateAirlineParams struct {
	Airlinecode       string `json:"airlinecode"`
	Airlinename       string `json:"airlinename"`
	ModeoftransportID int32  `json:"modeoftransport_id"`
}

func (q *Queries) CreateAirline(ctx context.Context, arg CreateAirlineParams) (Airline, error) {
	row := q.db.QueryRowContext(ctx, createAirline, arg.Airlinecode, arg.Airlinename, arg.ModeoftransportID)
	var i Airline
	err := row.Scan(
		&i.ID,
		&i.Airlinecode,
		&i.Airlinename,
		&i.ModeoftransportID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const deleteAirline = `-- name: DeleteAirline :exec
DELETE FROM airlines WHERE id= $1
`

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

const getAirline = `-- name: GetAirline :one
SELECT id, airlinecode, airlinename, modeoftransport_id, status, created_at FROM airlines
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetAirline(ctx context.Context, id int64) (Airline, error) {
	row := q.db.QueryRowContext(ctx, getAirline, id)
	var i Airline
	err := row.Scan(
		&i.ID,
		&i.Airlinecode,
		&i.Airlinename,
		&i.ModeoftransportID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const listAirlines = `-- name: ListAirlines :many
SELECT id, airlinecode, airlinename, modeoftransport_id, status, created_at from airlines
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListAirlines(ctx context.Context, arg ListAirlinesParams) ([]Airline, error) {
	rows, err := q.db.QueryContext(ctx, listAirlines, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Airline{}
	for rows.Next() {
		var i Airline
		if err := rows.Scan(
			&i.ID,
			&i.Airlinecode,
			&i.Airlinename,
			&i.ModeoftransportID,
			&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 updateAirline = `-- name: UpdateAirline :one
UPDATE airlines
  set 
    airlinecode = $2,
    airlinename = $3,
    modeoftransport_id = $4
WHERE id = $1
RETURNING id, airlinecode, airlinename, modeoftransport_id, status, created_at
`

type UpdateAirlineParams struct {
	ID                int64  `json:"id"`
	Airlinecode       string `json:"airlinecode"`
	Airlinename       string `json:"airlinename"`
	ModeoftransportID int32  `json:"modeoftransport_id"`
}

func (q *Queries) UpdateAirline(ctx context.Context, arg UpdateAirlineParams) (Airline, error) {
	row := q.db.QueryRowContext(ctx, updateAirline,
		arg.ID,
		arg.Airlinecode,
		arg.Airlinename,
		arg.ModeoftransportID,
	)
	var i Airline
	err := row.Scan(
		&i.ID,
		&i.Airlinecode,
		&i.Airlinename,
		&i.ModeoftransportID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}
