import 'dart:async';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/domain/entities/custom.dart';
import 'package:fcs/domain/entities/discount_rate.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';

class ShipmentRateModel extends BaseModel {
  final log = Logger('ShipmentRateModel');

  StreamSubscription<QuerySnapshot> listener;

  List<Rate> rates = [
    Rate(
        id: '1', name: 'general_cargo', description: 'General Cargo', price: 6),
    Rate(id: '2', name: 'medicine', description: 'Medicine', price: 7),
    Rate(
        id: '3',
        name: 'dangerous_cargo',
        description: 'Dangerous Cargo',
        price: 8),
  ];

  List<Custom> customs = [
    Custom(productType: 'Phone', fee: 40),
    Custom(productType: 'Max Book', fee: 40)
  ];

  List<DiscountRate> discountsByWeight = [
    DiscountRate(weight: 50, discountRate: 0.25),
    DiscountRate(weight: 100, discountRate: 0.50)
  ];

  int freeDeliveryWeight = 10;

  void initUser(user) {
    super.initUser(user);
  }

  @override
  logout() async {
    if (listener != null) await listener.cancel();
    rates = [];
  }
}
