const lineRepo = require("../repositories/lineRepo") const stationRepo = require("../repositories/stationRepo") const platformRepo = require("../repositories/platformRepo") const platformLineRepo = require("../repositories/platformLineRepo") /* ---------- LINES ---------- */ async function getAllLines() { return await lineRepo.findAllLines() } async function getLineById({ lineId }) { return await lineRepo.findLineById(lineId) } async function getLinesByTransportType({ transportTypeId }) { return await lineRepo.findLinesByTransportType(transportTypeId) } async function createLine({ code, name, textColorHex, backColorHex, transportTypeId }) { return await lineRepo.createLine( code, name, textColorHex, backColorHex, transportTypeId ) } async function updateLine({ lineId, updateData }) { return await lineRepo.updateLine(lineId, updateData) } async function deleteLine({ lineId }) { return await lineRepo.deleteLine(lineId) } /* ---------- STATIONS ---------- */ async function getAllStations() { return await stationRepo.findAllStations() } async function getStationById({ stationId }) { return await stationRepo.findStationById(stationId) } async function getStationsByDistance({ latitude, longitude, radiusKm }) { return await stationRepo.findStationsByDistance( latitude, longitude, radiusKm ) } async function getAccessibleStations({ latitude, longitude, radiusKm }) { return await stationRepo.findAccessibleStations( latitude, longitude, radiusKm ) } async function createStation({ name, description }) { return await stationRepo.createStation(name, description) } async function updateStation({ stationId, updateData }) { return await stationRepo.updateStation(stationId, updateData) } async function deleteStation({ stationId }) { return await stationRepo.deleteStation(stationId) } /* ---------- PLATFORMS ---------- */ async function getPlatformsByStation({ stationId }) { return await platformRepo.findPlatformsByStation(stationId) } async function getPlatformById({ platformId }) { return await platformRepo.findPlatformById(platformId) } async function createPlatform({ stationId, name, direction, latitude, longitude, isPRM = false, hasElevator = false }) { return await platformRepo.createPlatform( stationId, name, direction, latitude, longitude, isPRM, hasElevator ) } async function updatePlatformAccessibility({ platformId, isPRM, hasElevator }) { return await platformRepo.updatePlatformAccessibility( platformId, isPRM, hasElevator ) } async function deletePlatform({ platformId }) { return await platformRepo.deletePlatform(platformId) } /* ---------- PLATFORM <-> LINES ---------- */ async function getStationLines({ stationId }) { return await platformLineRepo.findLinesByStation(stationId) } async function getPlatformLines({ platformId }) { return await platformLineRepo.findLinesByPlatform(platformId) } async function getLineStations({ lineId, directionId = 0 }) { return await platformLineRepo.findStationsByLine(lineId, directionId) } async function addLineToPlatform({ platformId, lineId, directionId = 0, orderInLine }) { return await platformLineRepo.addLineToPlatform( platformId, lineId, directionId, orderInLine ) } async function removeLineFromPlatform({ platformId, lineId, directionId = 0 }) { return await platformLineRepo.removeLineFromPlatform( platformId, lineId, directionId ) } async function updatePlatformLineOrder({ platformLineId, orderInLine }) { return await platformLineRepo.updateOrder(platformLineId, orderInLine) } /* ---------- VALIDATION ---------- */ const DEFAULT_RADIUS_M = 100 async function findNearestPlatformForLine({ lineId, latitude, longitude, radiusM = DEFAULT_RADIUS_M }) { return await platformRepo.findNearestPlatformForLine( lineId, latitude, longitude, radiusM ) } module.exports = { getAllLines, getLineById, getLinesByTransportType, createLine, updateLine, deleteLine, getAllStations, getStationById, getStationsByDistance, getAccessibleStations, createStation, updateStation, deleteStation, getPlatformsByStation, getPlatformById, createPlatform, updatePlatformAccessibility, deletePlatform, getStationLines, getPlatformLines, getLineStations, addLineToPlatform, removeLineFromPlatform, updatePlatformLineOrder, findNearestPlatformForLine }