'decimal:6', 'is_default' => 'boolean', 'active' => 'boolean', ]; } public static function defaultFor(string $modality): ?self { return static::query() ->where('modality', $modality) ->where('is_default', true) ->where('active', true) ->first(); } /** * The cheapest active model always wins the default flag, since Runware's * own model-search API doesn't expose pricing — this locally-entered * table is the only place "cheapest" can be computed from. */ public static function recomputeDefault(string $modality): void { static::query()->where('modality', $modality)->update(['is_default' => false]); $cheapest = static::query() ->where('modality', $modality) ->where('active', true) ->orderBy('price_usd') ->orderBy('id') ->first(); $cheapest?->update(['is_default' => true]); } }