import 'dart:io';

import 'package:json_annotation/json_annotation.dart';

part 'orders_model.g.dart';

/// Created by Haoyi on 2022/7/27

@JsonSerializable()
class OrdersReport {
  // android
  @JsonKey(name: 'orderType', defaultValue: 0)
  int? orderType;
  @JsonKey(name: 'packageName')
  String? packageName;
  @JsonKey(name: 'productId')
  String? productId;
  @JsonKey(name: 'subscriptionId')
  String? subscriptionId;
  @JsonKey(name: 'token')
  String? token;

  // ios
  @JsonKey(name: 'bundleId')
  String? bundleId;
  @JsonKey(name: 'receipt')
  String? receipt;
  @JsonKey(name: 'sku')
  String? sku;
  @JsonKey(name: 'country')
  String? countryCode;

  // general
  @JsonKey(name: 'price')
  String? price;
  @JsonKey(name: 'currency')
  String? currency;

  OrdersReport(
      {this.orderType,
      this.token,
      this.packageName,
      this.productId,
      this.subscriptionId,
      this.bundleId,
      this.receipt,
      this.price,
      this.currency,
      this.sku,
      this.countryCode});

  @override
  String toString() {
    final StringBuffer sb = StringBuffer();
    sb.writeln("[OrdersReport]");
    sb.writeln("  productId: $productId");
    sb.writeln("  price: $price");
    sb.writeln("  currency: $currency");
    if (Platform.isAndroid) {
      sb.writeln("  orderType: $orderType");
      sb.writeln("  packageName: $packageName");
      sb.writeln("  subscriptionId: $subscriptionId");
      sb.writeln("  token: $token");
    } else if (Platform.isIOS) {
      sb.writeln("  bundleId: $bundleId");
      sb.writeln("  receipt: $receipt");
      sb.writeln("  sku: $sku");
      sb.writeln("  countryCode: $countryCode");
    }
    return sb
        .toString(); //'OrdersReport{orderType: $orderType, packageName: $packageName, productId: $productId, subscriptionId: $subscriptionId, token: $token, bundleId: $bundleId, receipt: $receipt, price: $price, currency: $currency, introductoryPrice: $introductoryPrice}';
  }

  factory OrdersReport.fromJson(Map<String, dynamic> json) => _$OrdersReportFromJson(json);

  Map<String, dynamic> toJson() => _$OrdersReportToJson(this);
}

@JsonSerializable()
class OrdersResponse {
  @JsonKey(name: 'usdPrice', defaultValue: 0.0)
  double usdPrice;

  OrdersResponse(this.usdPrice);

  factory OrdersResponse.fromJson(Map<String, dynamic> json) => _$OrdersResponseFromJson(json);

  Map<String, dynamic> toJson() => _$OrdersResponseToJson(this);

  @override
  String toString() {
    return 'OrdersResponse{usdPrice:$usdPrice}';
  }
}
