import 'dart:io' show Platform;

import 'package:dio/dio.dart';

import '../models/version/app_version.dart';

/// 版本检查 API 服务
class VersionService {
  const VersionService(this._dio);

  final Dio _dio;

  /// 获取最新版本信息 — POST uc/ancillary/system/app/version/{platform}
  /// platform: 0=Android, 1=iOS（与数据库 app_revision.platform 字段一致）
  Future<AppVersion?> getLatestVersion() async {
    final platform = Platform.isIOS ? 1 : 0;
    final response = await _dio.post<Map<String, dynamic>>(
      'uc/ancillary/system/app/version/$platform',
    );
    final data = response.data?['data'];
    if (data is Map<String, dynamic>) {
      return AppVersion.fromJson(data);
    }
    return null;
  }
}
