import 'package:json_annotation/json_annotation.dart';
import 'package:niogu_ecommerce_v1/core/models/tenant_payment_method_model.dart';
import 'package:niogu_ecommerce_v1/core/utils/converter.dart';

part 'tenant_model.g.dart';

@JsonSerializable()
class TenantModel {
  final String uuid;

  @JsonKey(name: 'business_code')
  final String businessCode;

  @JsonKey(name: 'business_name')
  final String businessName;

  @JsonKey(name: 'business_email')
  final String? businessEmail;

  @JsonKey(name: 'business_phone')
  final String? businessPhone;

  @JsonKey(name: 'business_type')
  final String? businessType;

  @JsonKey(name: 'server_logo_url')
  final String? serverLogoUrl;

  final String? subdomain;

  @JsonKey(name: 'online_store_name')
  final String? onlineStoreName;

  @JsonKey(name: 'online_open_time')
  final String? onlineOpenTime;

  @JsonKey(name: 'online_close_time')
  final String? onlineCloseTime;

  @JsonKey(name: 'is_close_service')
  final bool? isCloseService;

  @JsonKey(name: 'preparation_time_minutes')
  final int? preparationTimeMinutes;

  @JsonKey(name: 'order_interval_minutes')
  final int? orderIntervalMinutes;

  @JsonKey(name: 'allow_cod')
  final bool? allowCod;

  @JsonKey(name: 'max_delivery_radius_km', fromJson: toDouble)
  final double? maxDeliveryRadiusKm;

  @JsonKey(name: 'delivery_fee_type')
  final String? deliveryFeeType;

  @JsonKey(name: 'delivery_flat_fee', fromJson: toDouble)
  final double? deliveryFlatFee;

  @JsonKey(name: 'delivery_fee_per_km', fromJson: toDouble)
  final double? deliveryFeePerKm;

  @JsonKey(name: 'delivery_base_fee', fromJson: toDouble)
  final double? deliveryBaseFee;

  @JsonKey(name: 'review_display_type')
  final String? reviewDisplayType;

  @JsonKey(name: 'review_display_policy')
  final String? reviewDisplayPolicy;

  @JsonKey(name: 'subscription_level')
  final String? subscriptionLevel;

  @JsonKey(name: 'limit_outlet')
  final int? limitOutlet;

  @JsonKey(name: 'subscription_expires_at')
  final String? subscriptionExpiresAt;

  @JsonKey(name: 'created_at')
  final String createdAt;

  @JsonKey(name: 'updated_at')
  final String updatedAt;

  @JsonKey(name: 'payment_methods')
  final List<TenantPaymentMethodModel> paymentMethods;

  const TenantModel({
    required this.uuid,
    required this.businessCode,
    required this.businessName,
    required this.businessEmail,
    required this.businessPhone,
    required this.businessType,
    required this.serverLogoUrl,
    required this.subdomain,
    required this.onlineStoreName,
    required this.onlineOpenTime,
    required this.onlineCloseTime,
    required this.isCloseService,
    required this.preparationTimeMinutes,
    required this.orderIntervalMinutes,
    required this.allowCod,
    required this.maxDeliveryRadiusKm,
    required this.deliveryFeeType,
    required this.deliveryFlatFee,
    required this.deliveryFeePerKm,
    required this.deliveryBaseFee,
    required this.reviewDisplayType,
    required this.reviewDisplayPolicy,
    required this.subscriptionLevel,
    required this.limitOutlet,
    required this.subscriptionExpiresAt,
    required this.createdAt,
    required this.updatedAt,
    required this.paymentMethods
  });

  factory TenantModel.fromJson(Map<String, dynamic> json) =>
      _$TenantModelFromJson(json);
  Map<String, dynamic> toJson() => _$TenantModelToJson(this);
}
