import 'package:dio/dio.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import '../../../common/network/dio_provider.dart'; import '../../ads/data/ads_api_client.dart'; class AppMallAuthToken { const AppMallAuthToken({ required this.authToken, required this.expiresIn, required this.sourceApp, required this.scene, }); final String authToken; final int expiresIn; final String sourceApp; final String scene; } class MallAuthApi { const MallAuthApi(this._dio); final Dio _dio; Future issueAppMallAuthToken() async { final response = await _dio.post>( '/api/v1/auth/mall/app-token', data: const [], options: protobufOptions(), ); final reply = ProtoMessage(response.data ?? const []); final token = reply.string(1).trim(); if (token.isEmpty) throw const FormatException('Missing mall auth token'); return AppMallAuthToken( authToken: token, expiresIn: reply.integer(2), sourceApp: reply.string(3), scene: reply.string(4), ); } } final mallAuthApiProvider = Provider( (ref) => MallAuthApi(ref.watch(dioProvider)), );