import { BaseModel } from '#database/base_model' import { MigrationRoute } from '../domain/firmware/firmware_catalog.js' import { Sort } from 'mongodb' export default class MigrationRouteModel extends BaseModel { static collectionName = 'migration_routes' static async findByIdentifier(identifier: string): Promise { return this.findOne({ identifier }) as Promise } static async findByProductClass( productClass: string, sort: Sort = { priority: -1 } ): Promise { const collection = this.getCollection() return collection.find({ productClass }).sort(sort).toArray() as unknown as Promise } static async createIfNotExists(data: Partial): Promise { const existing = await this.findOne({ identifier: data.identifier }) if (existing) { throw new Error(`Migration route with identifier '${data.identifier}' already exists`) } return this.create(data) as Promise } static async deleteByIdentifier(identifier: string): Promise { return this.deleteOne({ identifier }) } }