import 'dart:io';

import 'package:dio/dio.dart';

class EditAccountModel {
  String? newLastName;
  String? newFirstName;
  String? password;
  File? avatarImage;
  EditAccountModel({this.password, this.newFirstName, this.newLastName});

  factory EditAccountModel.zero() => EditAccountModel();

  Future<Map<String, dynamic>> toJson() async {
    String? fileName = avatarImage?.path.split('/').last;
    MultipartFile? file;
    if (avatarImage != null) {
      file =
          await MultipartFile.fromFile(avatarImage!.path, filename: fileName);
    }

    Map<String, dynamic> data = {
      "password": password,
      "_method": 'put',
      if (newFirstName != null) "first_name": newFirstName,
      if (newLastName != null) "last_name": newLastName,
      if (avatarImage != null) 'avatar': file,
    };

    return data;
  }
}
