import 'package:tugas_akhir_supabase/domain/entities/field.dart';

class FieldModel extends Field {
  const FieldModel({
    required String id,
    required String name,
    required double area,
    required String userId,
    String? description,
    String? location,
  }) : super(
          id: id,
          name: name,
          area: area,
          userId: userId,
          description: description,
          location: location,
        );

  factory FieldModel.fromJson(Map<String, dynamic> json) {
    return FieldModel(
      id: json['id'] as String,
      name: json['name'] as String,
      area: (json['area'] is double)
          ? json['area']
          : double.tryParse(json['area'].toString()) ?? 0.0,
      userId: json['user_id'] as String,
      description: json['description'] as String?,
      location: json['location'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'area': area,
      'user_id': userId,
      'description': description,
      'location': location,
    };
  }

  factory FieldModel.fromEntity(Field entity) {
    return FieldModel(
      id: entity.id,
      name: entity.name,
      area: entity.area,
      userId: entity.userId,
      description: entity.description,
      location: entity.location,
    );
  }
} 