
import 'package:satu/core/utils/utils_parse.dart';

import 'items_bean.dart';
import 'operator_bean.dart';

class SellRequest {
  String type = 'g';
  List<ItemBean> items = [];
  double card = 0;
  double nal = 0;
  String? invoiceId;
  String? section;
  OperatorBean? operator;
  String? contragent;

  static SellRequest fromMap(dynamic map) {
    final SellRequest sellRequestBean = SellRequest();
    sellRequestBean.type = cast<String>(map['type']) ?? 'g';
    if(map['items'] !=null) {
      sellRequestBean.items.addAll(
          (map['items'] as List).map((o) => ItemBean.fromMap(o))
      );
    }
    sellRequestBean.card = cast<double>(map['card']) ?? 0;
    sellRequestBean.nal = cast<double>(map['nal']) ?? 0;
    sellRequestBean.invoiceId = cast<String>(map['invoice_id']);
    sellRequestBean.section = cast<String>(map['section']);
    sellRequestBean.operator = OperatorBean.fromMap(map['operator']);
    sellRequestBean.contragent = cast<String>(map['contragent']);
    return sellRequestBean;
  }

  Map<String, dynamic> toJson() => {
    'type': type,
    'items': items,
    'card': card,
    'nal': nal,
    'invoice_id': invoiceId,
    'section': section,
    'operator': operator,
    'contragent': contragent,
  };
}

