class FileResponseModel {
  final FileModel data;
  final String message;
  final bool success;

  FileResponseModel({
    required this.data,
    required this.message,
    required this.success,
  });

  factory FileResponseModel.fromJson(Map<String, dynamic> json) {
    return FileResponseModel(
      data: FileModel.fromJson(json['data']),
      message: json['message'] as String,
      success: json['success'] as bool,
    );
  }

  Map<String, dynamic> toJson() => {
        'data': data.toJson(),
        'message': message,
        'success': success,
      };

  factory FileResponseModel.fromMap(Map<String, dynamic> map) =>
      FileResponseModel.fromJson(map);

  Map<String, dynamic> toMap() => toJson();

  FileResponseModel copyWith({
    FileModel? data,
    String? message,
    bool? success,
  }) {
    return FileResponseModel(
      data: data ?? this.data,
      message: message ?? this.message,
      success: success ?? this.success,
    );
  }

  @override
  String toString() =>
      'FileResponseModel(data: $data, message: $message, success: $success)';
}

class FileModel {
  final String id;
  final String organizationId;
  final String userId;
  final String fileName;
  final String originalName;
  final String fileUrl;
  final int fileSize;
  final String mimeType;
  final String fileType;
  final String uploadPath;
  final bool isPublic;
  final DateTime createdAt;
  final DateTime updatedAt;

  FileModel({
    required this.id,
    required this.organizationId,
    required this.userId,
    required this.fileName,
    required this.originalName,
    required this.fileUrl,
    required this.fileSize,
    required this.mimeType,
    required this.fileType,
    required this.uploadPath,
    required this.isPublic,
    required this.createdAt,
    required this.updatedAt,
  });

  factory FileModel.fromJson(Map<String, dynamic> json) {
    return FileModel(
      id: json['id'] as String,
      organizationId: json['organization_id'] as String,
      userId: json['user_id'] as String,
      fileName: json['file_name'] as String,
      originalName: json['original_name'] as String,
      fileUrl: json['file_url'] as String,
      fileSize: json['file_size'] as int,
      mimeType: json['mime_type'] as String,
      fileType: json['file_type'] as String,
      uploadPath: json['upload_path'] as String,
      isPublic: json['is_public'] as bool,
      createdAt: DateTime.parse(json['created_at'] as String),
      updatedAt: DateTime.parse(json['updated_at'] as String),
    );
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        'organization_id': organizationId,
        'user_id': userId,
        'file_name': fileName,
        'original_name': originalName,
        'file_url': fileUrl,
        'file_size': fileSize,
        'mime_type': mimeType,
        'file_type': fileType,
        'upload_path': uploadPath,
        'is_public': isPublic,
        'created_at': createdAt.toIso8601String(),
        'updated_at': updatedAt.toIso8601String(),
      };

  factory FileModel.fromMap(Map<String, dynamic> map) =>
      FileModel.fromJson(map);

  Map<String, dynamic> toMap() => toJson();

  FileModel copyWith({
    String? id,
    String? organizationId,
    String? userId,
    String? fileName,
    String? originalName,
    String? fileUrl,
    int? fileSize,
    String? mimeType,
    String? fileType,
    String? uploadPath,
    bool? isPublic,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return FileModel(
      id: id ?? this.id,
      organizationId: organizationId ?? this.organizationId,
      userId: userId ?? this.userId,
      fileName: fileName ?? this.fileName,
      originalName: originalName ?? this.originalName,
      fileUrl: fileUrl ?? this.fileUrl,
      fileSize: fileSize ?? this.fileSize,
      mimeType: mimeType ?? this.mimeType,
      fileType: fileType ?? this.fileType,
      uploadPath: uploadPath ?? this.uploadPath,
      isPublic: isPublic ?? this.isPublic,
      createdAt: createdAt ?? this.createdAt,
      updatedAt: updatedAt ?? this.updatedAt,
    );
  }

  @override
  String toString() {
    return 'FileModel(id: $id, organizationId: $organizationId, userId: $userId, fileName: $fileName, originalName: $originalName, fileUrl: $fileUrl, fileSize: $fileSize, mimeType: $mimeType, fileType: $fileType, uploadPath: $uploadPath, isPublic: $isPublic, createdAt: $createdAt, updatedAt: $updatedAt)';
  }
}
