import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/widgets.dart';
import 'package:json_annotation/json_annotation.dart';

import '../../../base/app_base_request.dart';

part 'upload_request.g.dart';

@JsonSerializable()
class UploadRequest extends AppBaseRequest {
  @JsonKey(ignore: true)
  File? file;

  UploadRequest({this.file});

  @override
  Map<String, dynamic> toJson() {
    final json = _$UploadRequestToJson(this);
    debugPrint('file path: ${file?.path}');
    if (file != null) {
      json['file'] = MultipartFile.fromFileSync(file!.path,
          contentType: DioMediaType('image', 'jpeg'));
    }
    return json;
  }
}
