// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: queries.sql package db import ( "context" "database/sql" "time" ) const addBuildingToAirportByUsername = `-- name: AddBuildingToAirportByUsername :execresult INSERT INTO airport_buildings (airport_id, building_id) VALUES ((select id from airports where user_id = (select id from users where username = ?)), ?) ` type AddBuildingToAirportByUsernameParams struct { Username string BuildingID uint32 } func (q *Queries) AddBuildingToAirportByUsername(ctx context.Context, arg AddBuildingToAirportByUsernameParams) (sql.Result, error) { return q.db.ExecContext(ctx, addBuildingToAirportByUsername, arg.Username, arg.BuildingID) } const buyPlaneForPlayer = `-- name: BuyPlaneForPlayer :execresult INSERT INTO player_planes (airport_id, plane_id, assigned_hangar_id, current_building_id, status) VALUES (?, ?, ?, ?, 'idle') ` type BuyPlaneForPlayerParams struct { AirportID uint32 PlaneID uint32 AssignedHangarID uint32 CurrentBuildingID sql.NullInt32 } // ============================================================================ // 5. FLEET & DYNAMIC INFRASTRUCTURE OPERATIONS // ============================================================================ func (q *Queries) BuyPlaneForPlayer(ctx context.Context, arg BuyPlaneForPlayerParams) (sql.Result, error) { return q.db.ExecContext(ctx, buyPlaneForPlayer, arg.AirportID, arg.PlaneID, arg.AssignedHangarID, arg.CurrentBuildingID, ) } const checkHangarOccupancy = `-- name: CheckHangarOccupancy :one SELECT COUNT(*) AS total_parked FROM player_planes WHERE current_building_id = ? ` func (q *Queries) CheckHangarOccupancy(ctx context.Context, currentBuildingID sql.NullInt32) (int64, error) { row := q.db.QueryRowContext(ctx, checkHangarOccupancy, currentBuildingID) var total_parked int64 err := row.Scan(&total_parked) return total_parked, err } const checkHangarOccupancyByUsername = `-- name: CheckHangarOccupancyByUsername :one SELECT COUNT(*) AS total_parked FROM player_planes pp JOIN airport_buildings ab ON pp.current_building_id = ab.id WHERE ab.airport_id = (select id from airports where user_id = (select id from users where username = ?)) AND ab.building_id = ? ` type CheckHangarOccupancyByUsernameParams struct { Username string BuildingID uint32 } func (q *Queries) CheckHangarOccupancyByUsername(ctx context.Context, arg CheckHangarOccupancyByUsernameParams) (int64, error) { row := q.db.QueryRowContext(ctx, checkHangarOccupancyByUsername, arg.Username, arg.BuildingID) var total_parked int64 err := row.Scan(&total_parked) return total_parked, err } const checkRunwayOccupancyByUsername = `-- name: CheckRunwayOccupancyByUsername :one -- SELECT COUNT(*) AS total_occupied FROM player_planes pp JOIN airport_buildings ab ON pp.current_building_id = ab.id WHERE ab.airport_id = (select id from airports where user_id = (select id from users where username = ?)) AND ab.building_id = ? ` type CheckRunwayOccupancyByUsernameParams struct { Username string BuildingID uint32 } // specific hangar func (q *Queries) CheckRunwayOccupancyByUsername(ctx context.Context, arg CheckRunwayOccupancyByUsernameParams) (int64, error) { row := q.db.QueryRowContext(ctx, checkRunwayOccupancyByUsername, arg.Username, arg.BuildingID) var total_occupied int64 err := row.Scan(&total_occupied) return total_occupied, err } const completeContract = `-- name: CompleteContract :exec UPDATE airport_contracts SET is_completed = TRUE WHERE id = ? ` func (q *Queries) CompleteContract(ctx context.Context, id uint32) error { _, err := q.db.ExecContext(ctx, completeContract, id) return err } const createAirportByUserName = `-- name: CreateAirportByUserName :execresult INSERT INTO airports (name, user_id, origin_country_id) VALUES (?, (SELECT id FROM users WHERE username = ?), ?) ` type CreateAirportByUserNameParams struct { Name string Username string OriginCountryID uint16 } // ============================================================================ // 2. AIRPORT CORE MANAGEMENT // ============================================================================ // airport row management func (q *Queries) CreateAirportByUserName(ctx context.Context, arg CreateAirportByUserNameParams) (sql.Result, error) { return q.db.ExecContext(ctx, createAirportByUserName, arg.Name, arg.Username, arg.OriginCountryID) } const createUser = `-- name: CreateUser :execresult INSERT INTO users (username, password_hash) VALUES (?, ?) ` type CreateUserParams struct { Username string PasswordHash string } // ============================================================================ // 1. AUTHENTICATION & USERS // ============================================================================ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (sql.Result, error) { return q.db.ExecContext(ctx, createUser, arg.Username, arg.PasswordHash) } const deleteAirportByUserName = `-- name: DeleteAirportByUserName :exec UPDATE airports SET is_deleted = TRUE WHERE user_id = (SELECT id FROM users WHERE username = ?) ` func (q *Queries) DeleteAirportByUserName(ctx context.Context, username string) error { _, err := q.db.ExecContext(ctx, deleteAirportByUserName, username) return err } const deleteUserByUsername = `-- name: DeleteUserByUsername :exec UPDATE users SET deleted_at = CURRENT_TIMESTAMP WHERE username = ? ` func (q *Queries) DeleteUserByUsername(ctx context.Context, username string) error { _, err := q.db.ExecContext(ctx, deleteUserByUsername, username) return err } const findAvailableInfrastructure = `-- name: FindAvailableInfrastructure :one SELECT ab.id FROM airport_buildings ab JOIN buildings b ON ab.building_id = b.id LEFT JOIN player_planes pp ON ab.id = pp.current_building_id WHERE ab.airport_id = ? AND b.operation_type = ? -- 'runway' or 'service' (service bay) AND b.operation_size = ? -- matches plane's aircraft_size requirement AND pp.id IS NULL -- Ensures no other plane is physically here right now LIMIT 1 ` type FindAvailableInfrastructureParams struct { AirportID uint32 OperationType NullBuildingsOperationType OperationSize NullBuildingsOperationSize } func (q *Queries) FindAvailableInfrastructure(ctx context.Context, arg FindAvailableInfrastructureParams) (uint32, error) { row := q.db.QueryRowContext(ctx, findAvailableInfrastructure, arg.AirportID, arg.OperationType, arg.OperationSize) var id uint32 err := row.Scan(&id) return id, err } const findAvailableInfrastructureForPlane = `-- name: FindAvailableInfrastructureForPlane :one SELECT ab.id FROM airport_buildings ab JOIN buildings b ON ab.building_id = b.id LEFT JOIN player_planes pp ON ab.id = pp.current_building_id WHERE ab.airport_id = (select id from airports where user_id = (select id from users where username = ?)) AND b.operation_type = ? -- 'runway' or 'service' (service bay) AND b.operation_size = ? -- matches plane's aircraft_size requirement AND pp.id IS NULL -- Ensures no other plane is physically here right now LIMIT 1 ` type FindAvailableInfrastructureForPlaneParams struct { Username string OperationType NullBuildingsOperationType OperationSize NullBuildingsOperationSize } func (q *Queries) FindAvailableInfrastructureForPlane(ctx context.Context, arg FindAvailableInfrastructureForPlaneParams) (uint32, error) { row := q.db.QueryRowContext(ctx, findAvailableInfrastructureForPlane, arg.Username, arg.OperationType, arg.OperationSize) var id uint32 err := row.Scan(&id) return id, err } const getActiveContracts = `-- name: GetActiveContracts :many SELECT id, title, required_product_id, required_amount, current_amount_delivered, is_completed, expires_at FROM airport_contracts WHERE airport_id = ? AND is_completed = FALSE AND expires_at > NOW() ` type GetActiveContractsRow struct { ID uint32 Title string RequiredProductID uint16 RequiredAmount uint32 CurrentAmountDelivered uint32 IsCompleted bool ExpiresAt time.Time } // ============================================================================ // 7. PROGRESSION CONTRACTS & ECONOMY LOGS // ============================================================================ func (q *Queries) GetActiveContracts(ctx context.Context, airportID uint32) ([]GetActiveContractsRow, error) { rows, err := q.db.QueryContext(ctx, getActiveContracts, airportID) if err != nil { return nil, err } defer rows.Close() var items []GetActiveContractsRow for rows.Next() { var i GetActiveContractsRow if err := rows.Scan( &i.ID, &i.Title, &i.RequiredProductID, &i.RequiredAmount, &i.CurrentAmountDelivered, &i.IsCompleted, &i.ExpiresAt, ); 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 getAirportBuildingsByUsername = `-- name: GetAirportBuildingsByUsername :many SELECT ab.id AS airport_building_id,b.building_type , b.id, b.name, b.min_level, b.construction_cost_cash, b.upgrade_tier, b.upgrade_cost_cash_to_uptier, b.building_type, b.capacity, b.storage_type, b.storage_subtype, b.effect_id, b.effect_value, b.operation_size, b.operation_type, b.passive_type, b.passive_rate FROM airport_buildings ab JOIN buildings b ON ab.building_id = b.id WHERE ab.airport_id = (select id from airports where user_id = (select id from users where username = ?)) ` type GetAirportBuildingsByUsernameRow struct { AirportBuildingID uint32 BuildingType BuildingsBuildingType ID uint32 Name string MinLevel uint32 ConstructionCostCash uint32 UpgradeTier sql.NullInt16 UpgradeCostCashToUptier sql.NullInt32 BuildingType_2 BuildingsBuildingType Capacity sql.NullInt32 StorageType NullBuildingsStorageType StorageSubtype NullBuildingsStorageSubtype EffectID sql.NullInt16 EffectValue sql.NullInt32 OperationSize NullBuildingsOperationSize OperationType NullBuildingsOperationType PassiveType NullBuildingsPassiveType PassiveRate sql.NullInt32 } func (q *Queries) GetAirportBuildingsByUsername(ctx context.Context, username string) ([]GetAirportBuildingsByUsernameRow, error) { rows, err := q.db.QueryContext(ctx, getAirportBuildingsByUsername, username) if err != nil { return nil, err } defer rows.Close() var items []GetAirportBuildingsByUsernameRow for rows.Next() { var i GetAirportBuildingsByUsernameRow if err := rows.Scan( &i.AirportBuildingID, &i.BuildingType, &i.ID, &i.Name, &i.MinLevel, &i.ConstructionCostCash, &i.UpgradeTier, &i.UpgradeCostCashToUptier, &i.BuildingType_2, &i.Capacity, &i.StorageType, &i.StorageSubtype, &i.EffectID, &i.EffectValue, &i.OperationSize, &i.OperationType, &i.PassiveType, &i.PassiveRate, ); 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 getAirportByUserId = `-- name: GetAirportByUserId :one SELECT id, name, user_id, origin_country_id, cash, current_passengers, max_passenger_capacity, current_fuel, max_fuel_capacity, is_available, player_level, experience_points, passenger_generation_rate, fuel_generation_rate, resources_last_updated_at, is_deleted FROM airports WHERE user_id = ? LIMIT 1 ` type GetAirportByUserIdRow struct { ID uint32 Name string UserID int32 OriginCountryID uint16 Cash uint64 CurrentPassengers uint32 MaxPassengerCapacity uint32 CurrentFuel uint32 MaxFuelCapacity uint32 IsAvailable bool PlayerLevel uint32 ExperiencePoints uint64 PassengerGenerationRate uint32 FuelGenerationRate uint32 ResourcesLastUpdatedAt time.Time IsDeleted sql.NullBool } func (q *Queries) GetAirportByUserId(ctx context.Context, userID int32) (GetAirportByUserIdRow, error) { row := q.db.QueryRowContext(ctx, getAirportByUserId, userID) var i GetAirportByUserIdRow err := row.Scan( &i.ID, &i.Name, &i.UserID, &i.OriginCountryID, &i.Cash, &i.CurrentPassengers, &i.MaxPassengerCapacity, &i.CurrentFuel, &i.MaxFuelCapacity, &i.IsAvailable, &i.PlayerLevel, &i.ExperiencePoints, &i.PassengerGenerationRate, &i.FuelGenerationRate, &i.ResourcesLastUpdatedAt, &i.IsDeleted, ) return i, err } const getAirportByUserName = `-- name: GetAirportByUserName :one SELECT id, name, user_id, origin_country_id, cash, current_passengers, max_passenger_capacity, current_fuel, max_fuel_capacity, is_available, player_level, experience_points ,passenger_generation_rate, fuel_generation_rate, resources_last_updated_at, is_deleted FROM airports WHERE user_id = (SELECT id FROM users WHERE username = ?) LIMIT 1 ` type GetAirportByUserNameRow struct { ID uint32 Name string UserID int32 OriginCountryID uint16 Cash uint64 CurrentPassengers uint32 MaxPassengerCapacity uint32 CurrentFuel uint32 MaxFuelCapacity uint32 IsAvailable bool PlayerLevel uint32 ExperiencePoints uint64 PassengerGenerationRate uint32 FuelGenerationRate uint32 ResourcesLastUpdatedAt time.Time IsDeleted sql.NullBool } func (q *Queries) GetAirportByUserName(ctx context.Context, username string) (GetAirportByUserNameRow, error) { row := q.db.QueryRowContext(ctx, getAirportByUserName, username) var i GetAirportByUserNameRow err := row.Scan( &i.ID, &i.Name, &i.UserID, &i.OriginCountryID, &i.Cash, &i.CurrentPassengers, &i.MaxPassengerCapacity, &i.CurrentFuel, &i.MaxFuelCapacity, &i.IsAvailable, &i.PlayerLevel, &i.ExperiencePoints, &i.PassengerGenerationRate, &i.FuelGenerationRate, &i.ResourcesLastUpdatedAt, &i.IsDeleted, ) return i, err } const getAllPlanes = `-- name: GetAllPlanes :many SELECT id, name, min_level, operation_cost_fuel, operation_cost_cash, max_passengers, travel_time_inseconds, operation_type, aircraft_size, aircraft_type, buying_cost_cash, completed_flight_experience, completed_flight_cash_reward, completed_flight_cargo_reward FROM planes ` func (q *Queries) GetAllPlanes(ctx context.Context) ([]Plane, error) { rows, err := q.db.QueryContext(ctx, getAllPlanes) if err != nil { return nil, err } defer rows.Close() var items []Plane for rows.Next() { var i Plane if err := rows.Scan( &i.ID, &i.Name, &i.MinLevel, &i.OperationCostFuel, &i.OperationCostCash, &i.MaxPassengers, &i.TravelTimeInseconds, &i.OperationType, &i.AircraftSize, &i.AircraftType, &i.BuyingCostCash, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, ); 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 getPlaneById = `-- name: GetPlaneById :one SELECT id, name, min_level, operation_cost_fuel, operation_cost_cash, max_passengers, travel_time_inseconds, operation_type, aircraft_size, aircraft_type, buying_cost_cash, completed_flight_experience, completed_flight_cash_reward, completed_flight_cargo_reward FROM planes WHERE id = ? ` func (q *Queries) GetPlaneById(ctx context.Context, id uint32) (Plane, error) { row := q.db.QueryRowContext(ctx, getPlaneById, id) var i Plane err := row.Scan( &i.ID, &i.Name, &i.MinLevel, &i.OperationCostFuel, &i.OperationCostCash, &i.MaxPassengers, &i.TravelTimeInseconds, &i.OperationType, &i.AircraftSize, &i.AircraftType, &i.BuyingCostCash, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, ) return i, err } const getPlanesByAircraftSize = `-- name: GetPlanesByAircraftSize :many SELECT id, name, min_level, operation_cost_fuel, operation_cost_cash, max_passengers, travel_time_inseconds, operation_type, aircraft_size, aircraft_type, buying_cost_cash, completed_flight_experience, completed_flight_cash_reward, completed_flight_cargo_reward FROM planes WHERE aircraft_size = ? ` func (q *Queries) GetPlanesByAircraftSize(ctx context.Context, aircraftSize PlanesAircraftSize) ([]Plane, error) { rows, err := q.db.QueryContext(ctx, getPlanesByAircraftSize, aircraftSize) if err != nil { return nil, err } defer rows.Close() var items []Plane for rows.Next() { var i Plane if err := rows.Scan( &i.ID, &i.Name, &i.MinLevel, &i.OperationCostFuel, &i.OperationCostCash, &i.MaxPassengers, &i.TravelTimeInseconds, &i.OperationType, &i.AircraftSize, &i.AircraftType, &i.BuyingCostCash, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, ); 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 getPlanesByAircraftType = `-- name: GetPlanesByAircraftType :many SELECT id, name, min_level, operation_cost_fuel, operation_cost_cash, max_passengers, travel_time_inseconds, operation_type, aircraft_size, aircraft_type, buying_cost_cash, completed_flight_experience, completed_flight_cash_reward, completed_flight_cargo_reward FROM planes WHERE aircraft_type = ? ` func (q *Queries) GetPlanesByAircraftType(ctx context.Context, aircraftType PlanesAircraftType) ([]Plane, error) { rows, err := q.db.QueryContext(ctx, getPlanesByAircraftType, aircraftType) if err != nil { return nil, err } defer rows.Close() var items []Plane for rows.Next() { var i Plane if err := rows.Scan( &i.ID, &i.Name, &i.MinLevel, &i.OperationCostFuel, &i.OperationCostCash, &i.MaxPassengers, &i.TravelTimeInseconds, &i.OperationType, &i.AircraftSize, &i.AircraftType, &i.BuyingCostCash, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, ); 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 getPlanesByMinLevel = `-- name: GetPlanesByMinLevel :many SELECT id, name, min_level, operation_cost_fuel, operation_cost_cash, max_passengers, travel_time_inseconds, operation_type, aircraft_size, aircraft_type, buying_cost_cash, completed_flight_experience, completed_flight_cash_reward, completed_flight_cargo_reward FROM planes WHERE min_level <= ? ` func (q *Queries) GetPlanesByMinLevel(ctx context.Context, minLevel uint32) ([]Plane, error) { rows, err := q.db.QueryContext(ctx, getPlanesByMinLevel, minLevel) if err != nil { return nil, err } defer rows.Close() var items []Plane for rows.Next() { var i Plane if err := rows.Scan( &i.ID, &i.Name, &i.MinLevel, &i.OperationCostFuel, &i.OperationCostCash, &i.MaxPassengers, &i.TravelTimeInseconds, &i.OperationType, &i.AircraftSize, &i.AircraftType, &i.BuyingCostCash, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, ); 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 getPlanesByOperationType = `-- name: GetPlanesByOperationType :many SELECT id, name, min_level, operation_cost_fuel, operation_cost_cash, max_passengers, travel_time_inseconds, operation_type, aircraft_size, aircraft_type, buying_cost_cash, completed_flight_experience, completed_flight_cash_reward, completed_flight_cargo_reward FROM planes WHERE operation_type = ? ` func (q *Queries) GetPlanesByOperationType(ctx context.Context, operationType PlanesOperationType) ([]Plane, error) { rows, err := q.db.QueryContext(ctx, getPlanesByOperationType, operationType) if err != nil { return nil, err } defer rows.Close() var items []Plane for rows.Next() { var i Plane if err := rows.Scan( &i.ID, &i.Name, &i.MinLevel, &i.OperationCostFuel, &i.OperationCostCash, &i.MaxPassengers, &i.TravelTimeInseconds, &i.OperationType, &i.AircraftSize, &i.AircraftType, &i.BuyingCostCash, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, ); 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 getPlanesReadyToLand = `-- name: GetPlanesReadyToLand :many SELECT pp.id AS player_plane_id, pp.airport_id, pp.assigned_hangar_id, p.completed_flight_experience, p.completed_flight_cash_reward, p.completed_flight_cargo_reward, p.operation_type FROM player_planes pp JOIN planes p ON pp.plane_id = p.id WHERE pp.status = 'flying' -- Uses your logic: flight_start_time + plane travel duration <= current clock AND ADDTIME(pp.flight_start_time, p.travel_time) <= NOW() ` type GetPlanesReadyToLandRow struct { PlayerPlaneID uint32 AirportID uint32 AssignedHangarID uint32 CompletedFlightExperience uint32 CompletedFlightCashReward sql.NullInt32 CompletedFlightCargoReward sql.NullInt32 OperationType PlanesOperationType } // ============================================================================ // 6. TIME-BASED FLIGHT ENGINE // ============================================================================ func (q *Queries) GetPlanesReadyToLand(ctx context.Context) ([]GetPlanesReadyToLandRow, error) { rows, err := q.db.QueryContext(ctx, getPlanesReadyToLand) if err != nil { return nil, err } defer rows.Close() var items []GetPlanesReadyToLandRow for rows.Next() { var i GetPlanesReadyToLandRow if err := rows.Scan( &i.PlayerPlaneID, &i.AirportID, &i.AssignedHangarID, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, &i.OperationType, ); 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 getPlanesReadyToLandByUsername = `-- name: GetPlanesReadyToLandByUsername :many SELECT pp.id AS player_plane_id, pp.airport_id, pp.assigned_hangar_id, p.completed_flight_experience, p.completed_flight_cash_reward, p.completed_flight_cargo_reward, p.operation_type FROM player_planes pp JOIN planes p ON pp.plane_id = p.id WHERE pp.status = 'flying' AND ADDTIME(pp.flight_start_time, p.travel_time) <= NOW() AND pp.airport_id = (select id from airports where user_id = (select id from users where username = ?)) ` type GetPlanesReadyToLandByUsernameRow struct { PlayerPlaneID uint32 AirportID uint32 AssignedHangarID uint32 CompletedFlightExperience uint32 CompletedFlightCashReward sql.NullInt32 CompletedFlightCargoReward sql.NullInt32 OperationType PlanesOperationType } // specific runway func (q *Queries) GetPlanesReadyToLandByUsername(ctx context.Context, username string) ([]GetPlanesReadyToLandByUsernameRow, error) { rows, err := q.db.QueryContext(ctx, getPlanesReadyToLandByUsername, username) if err != nil { return nil, err } defer rows.Close() var items []GetPlanesReadyToLandByUsernameRow for rows.Next() { var i GetPlanesReadyToLandByUsernameRow if err := rows.Scan( &i.PlayerPlaneID, &i.AirportID, &i.AssignedHangarID, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, &i.OperationType, ); 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 getPlayerFleet = `-- name: GetPlayerFleet :many SELECT pp.id AS player_plane_id, pp.status, pp.updated_at, pp.flight_start_time, pp.current_building_id, pp.assigned_hangar_id,p.id, p.name, p.min_level, p.operation_cost_fuel, p.operation_cost_cash, p.max_passengers, p.travel_time_inseconds, p.operation_type, p.aircraft_size, p.aircraft_type, p.buying_cost_cash, p.completed_flight_experience, p.completed_flight_cash_reward, p.completed_flight_cargo_reward FROM player_planes pp JOIN planes p ON pp.plane_id = p.id WHERE pp.airport_id = ? ` type GetPlayerFleetRow struct { PlayerPlaneID uint32 Status PlayerPlanesStatus UpdatedAt sql.NullTime FlightStartTime sql.NullTime CurrentBuildingID sql.NullInt32 AssignedHangarID uint32 ID uint32 Name string MinLevel uint32 OperationCostFuel uint32 OperationCostCash uint32 MaxPassengers sql.NullInt32 TravelTimeInseconds uint32 OperationType PlanesOperationType AircraftSize PlanesAircraftSize AircraftType PlanesAircraftType BuyingCostCash uint32 CompletedFlightExperience uint32 CompletedFlightCashReward sql.NullInt32 CompletedFlightCargoReward sql.NullInt32 } func (q *Queries) GetPlayerFleet(ctx context.Context, airportID uint32) ([]GetPlayerFleetRow, error) { rows, err := q.db.QueryContext(ctx, getPlayerFleet, airportID) if err != nil { return nil, err } defer rows.Close() var items []GetPlayerFleetRow for rows.Next() { var i GetPlayerFleetRow if err := rows.Scan( &i.PlayerPlaneID, &i.Status, &i.UpdatedAt, &i.FlightStartTime, &i.CurrentBuildingID, &i.AssignedHangarID, &i.ID, &i.Name, &i.MinLevel, &i.OperationCostFuel, &i.OperationCostCash, &i.MaxPassengers, &i.TravelTimeInseconds, &i.OperationType, &i.AircraftSize, &i.AircraftType, &i.BuyingCostCash, &i.CompletedFlightExperience, &i.CompletedFlightCashReward, &i.CompletedFlightCargoReward, ); 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 getPlayerPlanesByUsername = `-- name: GetPlayerPlanesByUsername :many SELECT pp.id AS player_plane_id, pp.id, pp.airport_id, pp.plane_id, pp.assigned_hangar_id, pp.current_building_id, pp.status, pp.updated_at, pp.flight_start_time FROM player_planes pp JOIN planes p ON pp.plane_id = p.id WHERE pp.airport_id = (select id from airports where user_id = (select id from users where username = ?)) ` type GetPlayerPlanesByUsernameRow struct { PlayerPlaneID uint32 ID uint32 AirportID uint32 PlaneID uint32 AssignedHangarID uint32 CurrentBuildingID sql.NullInt32 Status PlayerPlanesStatus UpdatedAt sql.NullTime FlightStartTime sql.NullTime } func (q *Queries) GetPlayerPlanesByUsername(ctx context.Context, username string) ([]GetPlayerPlanesByUsernameRow, error) { rows, err := q.db.QueryContext(ctx, getPlayerPlanesByUsername, username) if err != nil { return nil, err } defer rows.Close() var items []GetPlayerPlanesByUsernameRow for rows.Next() { var i GetPlayerPlanesByUsernameRow if err := rows.Scan( &i.PlayerPlaneID, &i.ID, &i.AirportID, &i.PlaneID, &i.AssignedHangarID, &i.CurrentBuildingID, &i.Status, &i.UpdatedAt, &i.FlightStartTime, ); 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 getUserByUsername = `-- name: GetUserByUsername :one SELECT id, username, password_hash FROM users WHERE username = ? LIMIT 1 ` type GetUserByUsernameRow struct { ID int32 Username string PasswordHash string } func (q *Queries) GetUserByUsername(ctx context.Context, username string) (GetUserByUsernameRow, error) { row := q.db.QueryRowContext(ctx, getUserByUsername, username) var i GetUserByUsernameRow err := row.Scan(&i.ID, &i.Username, &i.PasswordHash) return i, err } const getUserIdByUsername = `-- name: GetUserIdByUsername :one SELECT id FROM users WHERE username = ? LIMIT 1 ` func (q *Queries) GetUserIdByUsername(ctx context.Context, username string) (int32, error) { row := q.db.QueryRowContext(ctx, getUserIdByUsername, username) var id int32 err := row.Scan(&id) return id, err } const logCompletedFlightRoute = `-- name: LogCompletedFlightRoute :exec INSERT INTO completed_flight_routes_log (origin_airport_id, destination_airport_id, start_time, end_time) VALUES (?, ?, ?, NOW()) ` type LogCompletedFlightRouteParams struct { OriginAirportID uint32 DestinationAirportID uint32 StartTime time.Time } func (q *Queries) LogCompletedFlightRoute(ctx context.Context, arg LogCompletedFlightRouteParams) error { _, err := q.db.ExecContext(ctx, logCompletedFlightRoute, arg.OriginAirportID, arg.DestinationAirportID, arg.StartTime) return err } const logCurrencyTransaction = `-- name: LogCurrencyTransaction :exec INSERT INTO currency_transaction_logs (airport_id, amount_changed, currency_type, reason) VALUES (?, ?, ?, ?) ` type LogCurrencyTransactionParams struct { AirportID uint32 AmountChanged int32 CurrencyType CurrencyTransactionLogsCurrencyType Reason string } func (q *Queries) LogCurrencyTransaction(ctx context.Context, arg LogCurrencyTransactionParams) error { _, err := q.db.ExecContext(ctx, logCurrencyTransaction, arg.AirportID, arg.AmountChanged, arg.CurrencyType, arg.Reason, ) return err } const updateAirportCash = `-- name: UpdateAirportCash :exec UPDATE airports SET cash = ? WHERE id = ? ` type UpdateAirportCashParams struct { Cash uint64 ID uint32 } func (q *Queries) UpdateAirportCash(ctx context.Context, arg UpdateAirportCashParams) error { _, err := q.db.ExecContext(ctx, updateAirportCash, arg.Cash, arg.ID) return err } const updateAirportCurrencies = `-- name: UpdateAirportCurrencies :exec UPDATE airports SET cash = ?, current_passengers = ?, current_fuel = ? WHERE id = ? ` type UpdateAirportCurrenciesParams struct { Cash uint64 CurrentPassengers uint32 CurrentFuel uint32 ID uint32 } // airport resource management func (q *Queries) UpdateAirportCurrencies(ctx context.Context, arg UpdateAirportCurrenciesParams) error { _, err := q.db.ExecContext(ctx, updateAirportCurrencies, arg.Cash, arg.CurrentPassengers, arg.CurrentFuel, arg.ID, ) return err } const updateAirportFuel = `-- name: UpdateAirportFuel :exec UPDATE airports SET current_fuel = ? WHERE id = ? ` type UpdateAirportFuelParams struct { CurrentFuel uint32 ID uint32 } func (q *Queries) UpdateAirportFuel(ctx context.Context, arg UpdateAirportFuelParams) error { _, err := q.db.ExecContext(ctx, updateAirportFuel, arg.CurrentFuel, arg.ID) return err } const updateAirportFuelRate = `-- name: UpdateAirportFuelRate :exec UPDATE airports SET fuel_generation_rate = ? WHERE id = ? ` type UpdateAirportFuelRateParams struct { FuelGenerationRate uint32 ID uint32 } func (q *Queries) UpdateAirportFuelRate(ctx context.Context, arg UpdateAirportFuelRateParams) error { _, err := q.db.ExecContext(ctx, updateAirportFuelRate, arg.FuelGenerationRate, arg.ID) return err } const updateAirportMaxFuel = `-- name: UpdateAirportMaxFuel :exec UPDATE airports SET max_fuel_capacity = ? WHERE id = ? ` type UpdateAirportMaxFuelParams struct { MaxFuelCapacity uint32 ID uint32 } func (q *Queries) UpdateAirportMaxFuel(ctx context.Context, arg UpdateAirportMaxFuelParams) error { _, err := q.db.ExecContext(ctx, updateAirportMaxFuel, arg.MaxFuelCapacity, arg.ID) return err } const updateAirportPassengerRate = `-- name: UpdateAirportPassengerRate :exec UPDATE airports SET passenger_generation_rate = ? WHERE id = ? ` type UpdateAirportPassengerRateParams struct { PassengerGenerationRate uint32 ID uint32 } func (q *Queries) UpdateAirportPassengerRate(ctx context.Context, arg UpdateAirportPassengerRateParams) error { _, err := q.db.ExecContext(ctx, updateAirportPassengerRate, arg.PassengerGenerationRate, arg.ID) return err } const updateAirportResources = `-- name: UpdateAirportResources :exec UPDATE airports SET current_fuel = LEAST( max_fuel_capacity, current_fuel + (fuel_generation_rate * TIMESTAMPDIFF(SECOND, resources_last_updated_at, NOW())) ), current_passengers = LEAST( max_passenger_capacity, current_passengers + (passenger_generation_rate * TIMESTAMPDIFF(SECOND, resources_last_updated_at, NOW())) ), resources_last_updated_at = NOW() WHERE id = ? ` func (q *Queries) UpdateAirportResources(ctx context.Context, id uint32) error { _, err := q.db.ExecContext(ctx, updateAirportResources, id) return err } const updateAirportResourcesUpdated = `-- name: UpdateAirportResourcesUpdated :exec update airports set resources_last_updated_at = ? where id = ? ` type UpdateAirportResourcesUpdatedParams struct { ResourcesLastUpdatedAt time.Time ID uint32 } func (q *Queries) UpdateAirportResourcesUpdated(ctx context.Context, arg UpdateAirportResourcesUpdatedParams) error { _, err := q.db.ExecContext(ctx, updateAirportResourcesUpdated, arg.ResourcesLastUpdatedAt, arg.ID) return err } const updateAirportmaxPassengers = `-- name: UpdateAirportmaxPassengers :exec UPDATE airports SET max_passenger_capacity = ? WHERE id = ? ` type UpdateAirportmaxPassengersParams struct { MaxPassengerCapacity uint32 ID uint32 } func (q *Queries) UpdateAirportmaxPassengers(ctx context.Context, arg UpdateAirportmaxPassengersParams) error { _, err := q.db.ExecContext(ctx, updateAirportmaxPassengers, arg.MaxPassengerCapacity, arg.ID) return err } const updateAirportpassengers = `-- name: UpdateAirportpassengers :exec UPDATE airports SET current_passengers = ? WHERE id = ? ` type UpdateAirportpassengersParams struct { CurrentPassengers uint32 ID uint32 } func (q *Queries) UpdateAirportpassengers(ctx context.Context, arg UpdateAirportpassengersParams) error { _, err := q.db.ExecContext(ctx, updateAirportpassengers, arg.CurrentPassengers, arg.ID) return err } const updateContractDelivery = `-- name: UpdateContractDelivery :exec UPDATE airport_contracts SET current_amount_delivered = current_amount_delivered + ? WHERE id = ? AND is_completed = FALSE ` type UpdateContractDeliveryParams struct { CurrentAmountDelivered uint32 ID uint32 } func (q *Queries) UpdateContractDelivery(ctx context.Context, arg UpdateContractDeliveryParams) error { _, err := q.db.ExecContext(ctx, updateContractDelivery, arg.CurrentAmountDelivered, arg.ID) return err } const updatePlaneState = `-- name: UpdatePlaneState :exec UPDATE player_planes SET current_building_id = ?, status = ?, flight_start_time = ? WHERE id = ? ` type UpdatePlaneStateParams struct { CurrentBuildingID sql.NullInt32 Status PlayerPlanesStatus FlightStartTime sql.NullTime ID uint32 } func (q *Queries) UpdatePlaneState(ctx context.Context, arg UpdatePlaneStateParams) error { _, err := q.db.ExecContext(ctx, updatePlaneState, arg.CurrentBuildingID, arg.Status, arg.FlightStartTime, arg.ID, ) return err } const updatePlayerPlaneState = `-- name: UpdatePlayerPlaneState :exec UPDATE player_planes SET current_building_id = ?, status = ?, flight_start_time = ? WHERE id = ? ` type UpdatePlayerPlaneStateParams struct { CurrentBuildingID sql.NullInt32 Status PlayerPlanesStatus FlightStartTime sql.NullTime ID uint32 } func (q *Queries) UpdatePlayerPlaneState(ctx context.Context, arg UpdatePlayerPlaneStateParams) error { _, err := q.db.ExecContext(ctx, updatePlayerPlaneState, arg.CurrentBuildingID, arg.Status, arg.FlightStartTime, arg.ID, ) return err } const updateUserPasswordByUserName = `-- name: UpdateUserPasswordByUserName :exec UPDATE users SET password_hash = ? WHERE username = ? ` type UpdateUserPasswordByUserNameParams struct { PasswordHash string Username string } func (q *Queries) UpdateUserPasswordByUserName(ctx context.Context, arg UpdateUserPasswordByUserNameParams) error { _, err := q.db.ExecContext(ctx, updateUserPasswordByUserName, arg.PasswordHash, arg.Username) return err } const addBuilding = `-- name: addBuilding :execresult INSERT INTO buildings (name,min_level,construction_cost_cash) VALUES (?, ?, ?) ` type addBuildingParams struct { Name string MinLevel uint32 ConstructionCostCash uint32 } func (q *Queries) addBuilding(ctx context.Context, arg addBuildingParams) (sql.Result, error) { return q.db.ExecContext(ctx, addBuilding, arg.Name, arg.MinLevel, arg.ConstructionCostCash) } const addOperationalBuilding = `-- name: addOperationalBuilding :execresult INSERT INTO buildings (name,min_level,construction_cost_cash,operation_type,operation_size) VALUES (?, ?, ?, ?, ?) ` type addOperationalBuildingParams struct { Name string MinLevel uint32 ConstructionCostCash uint32 OperationType NullBuildingsOperationType OperationSize NullBuildingsOperationSize } func (q *Queries) addOperationalBuilding(ctx context.Context, arg addOperationalBuildingParams) (sql.Result, error) { return q.db.ExecContext(ctx, addOperationalBuilding, arg.Name, arg.MinLevel, arg.ConstructionCostCash, arg.OperationType, arg.OperationSize, ) } const addPassiveProductionBuilding = `-- name: addPassiveProductionBuilding :execresult INSERT INTO buildings (name,min_level,construction_cost_cash,passive_type,passive_rate) VALUES (?, ?, ?, ?, ?) ` type addPassiveProductionBuildingParams struct { Name string MinLevel uint32 ConstructionCostCash uint32 PassiveType NullBuildingsPassiveType PassiveRate sql.NullInt32 } func (q *Queries) addPassiveProductionBuilding(ctx context.Context, arg addPassiveProductionBuildingParams) (sql.Result, error) { return q.db.ExecContext(ctx, addPassiveProductionBuilding, arg.Name, arg.MinLevel, arg.ConstructionCostCash, arg.PassiveType, arg.PassiveRate, ) } const addPlane = `-- name: addPlane :execresult INSERT INTO planes (name, aircraft_size,operation_type,aircraft_type ,min_level, operation_cost_fuel, operation_cost_cash, max_passengers, travel_time_inSeconds,buying_cost_cash, completed_flight_experience, completed_flight_cash_reward, completed_flight_cargo_reward) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` type addPlaneParams struct { Name string AircraftSize PlanesAircraftSize OperationType PlanesOperationType AircraftType PlanesAircraftType MinLevel uint32 OperationCostFuel uint32 OperationCostCash uint32 MaxPassengers sql.NullInt32 TravelTimeInseconds uint32 BuyingCostCash uint32 CompletedFlightExperience uint32 CompletedFlightCashReward sql.NullInt32 CompletedFlightCargoReward sql.NullInt32 } // planes & fleet management func (q *Queries) addPlane(ctx context.Context, arg addPlaneParams) (sql.Result, error) { return q.db.ExecContext(ctx, addPlane, arg.Name, arg.AircraftSize, arg.OperationType, arg.AircraftType, arg.MinLevel, arg.OperationCostFuel, arg.OperationCostCash, arg.MaxPassengers, arg.TravelTimeInseconds, arg.BuyingCostCash, arg.CompletedFlightExperience, arg.CompletedFlightCashReward, arg.CompletedFlightCargoReward, ) } const addPlaneToAirportByUsername = `-- name: addPlaneToAirportByUsername :execresult INSERT INTO player_planes (airport_id, plane_id, assigned_hangar_id, current_building_id, status) VALUES ((select id from airports where user_id = (select id from users where username = ?)), ?, ?, ?, 'idle') ` type addPlaneToAirportByUsernameParams struct { Username string PlaneID uint32 AssignedHangarID uint32 CurrentBuildingID sql.NullInt32 } func (q *Queries) addPlaneToAirportByUsername(ctx context.Context, arg addPlaneToAirportByUsernameParams) (sql.Result, error) { return q.db.ExecContext(ctx, addPlaneToAirportByUsername, arg.Username, arg.PlaneID, arg.AssignedHangarID, arg.CurrentBuildingID, ) } const addStorageBuilding = `-- name: addStorageBuilding :execresult INSERT INTO buildings (name,min_level,construction_cost_cash,capacity,storage_type,storage_subtype) VALUES (?, ?, ?, ?, ?, ?) ` type addStorageBuildingParams struct { Name string MinLevel uint32 ConstructionCostCash uint32 Capacity sql.NullInt32 StorageType NullBuildingsStorageType StorageSubtype NullBuildingsStorageSubtype } // ============================================================================ // 3. WAREHOUSE & INVENTORY SYSTEM // ============================================================================ // ============================================================================ // 4. BUILDINGS & PRODUCTION ENGINE // ============================================================================ func (q *Queries) addStorageBuilding(ctx context.Context, arg addStorageBuildingParams) (sql.Result, error) { return q.db.ExecContext(ctx, addStorageBuilding, arg.Name, arg.MinLevel, arg.ConstructionCostCash, arg.Capacity, arg.StorageType, arg.StorageSubtype, ) } const updatePlayerExperience = `-- name: updatePlayerExperience :exec UPDATE airports SET experience_points = ? WHERE id = ? ` type updatePlayerExperienceParams struct { ExperiencePoints uint64 ID uint32 } func (q *Queries) updatePlayerExperience(ctx context.Context, arg updatePlayerExperienceParams) error { _, err := q.db.ExecContext(ctx, updatePlayerExperience, arg.ExperiencePoints, arg.ID) return err } const updatePlayerLevel = `-- name: updatePlayerLevel :exec UPDATE airports SET player_level = ? WHERE id = ? ` type updatePlayerLevelParams struct { PlayerLevel uint32 ID uint32 } func (q *Queries) updatePlayerLevel(ctx context.Context, arg updatePlayerLevelParams) error { _, err := q.db.ExecContext(ctx, updatePlayerLevel, arg.PlayerLevel, arg.ID) return err }