import 'dart:io';

import 'package:dio/dio.dart';

class AddCardModel {
  String name;
  int categoryId;
  int cityId;
  String phoneNumber;
  String? address;
  String? postalCode;
  String webSite;
  String service;
  String additionalData;
  List<File>? images;

  AddCardModel(
      {required this.name,
      required this.categoryId,
      required this.cityId,
      required this.phoneNumber,
      this.address,
      this.postalCode,
      required this.webSite,
      required this.service,
      required this.additionalData,
      this.images});

  Map<String, dynamic> toJson() {
    Map<String, dynamic> result = {
      "name": name,
      "city_id": cityId,
      "category_id": categoryId,
      "phone_number1": phoneNumber,
      "website": webSite,
      "services": service,
      "additional_data": additionalData,
    };
    if (address != null && postalCode != " ") {
      result["address"] = address;
    }
    if (postalCode != null && postalCode != " ") {
      result["postal_code"] = postalCode;
    }
    if (images != null && images != []) {
      for (int i = 0; i < images!.length; i++) {
        result["images[${i + 1}]"] = MultipartFile.fromFileSync(images![i].path);
      }
    }
    return result;
  }

  factory AddCardModel.zero() => AddCardModel(
      name: "", categoryId: 0, cityId: 0, phoneNumber: "", webSite: "", service: "", additionalData: "", images: []);
}
