import 'package:rasadyar_core/core.dart';

part 'poultry_location_model.freezed.dart';
part 'poultry_location_model.g.dart';

@freezed
abstract class PoultryLocationModel with _$PoultryLocationModel {
  const factory PoultryLocationModel({
    int? id,
    String? unitName,
    @JsonKey(name: 'Lat') double? lat,
    @JsonKey(name: 'Long') double? long,
    User? user,
    List<Hatching>? hatching,
    Address? address,
    String? breedingUniqueId,
    @JsonKey(includeFromJson: false, includeToJson: false) LatLng? latLng,
  }) = _PoultryLocationModel;

  factory PoultryLocationModel.fromJson(Map<String, dynamic> json) =>
      _$PoultryLocationModelFromJson(json).copyWith(
        latLng: (json['Lat'] != null && json['Long'] != null)
            ? LatLng(json['Lat'] as double, json['Long'] as double)
            : null,
      );
}

@freezed
abstract class User with _$User {
  const factory User({String? fullname, String? mobile}) = _User;

  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}

@freezed
abstract class Hatching with _$Hatching {
  const factory Hatching({int? leftOver, int? chickenAge, DateTime? date, String? licenceNumber}) =
      _Hatching;

  factory Hatching.fromJson(Map<String, dynamic> json) => _$HatchingFromJson(json);
}

@freezed
abstract class Address with _$Address {
  const factory Address({City? city, String? address}) = _Address;

  factory Address.fromJson(Map<String, dynamic> json) => _$AddressFromJson(json);
}

@freezed
abstract class City with _$City {
  const factory City({String? name}) = _City;

  factory City.fromJson(Map<String, dynamic> json) => _$CityFromJson(json);
}
