// ignore_for_file: non_constant_identifier_names, camel_case_types, file_namesimport, file_names, unnecessary_null_comparison, prefer_null_aware_operators
// WARNING: This code is auto-generated by Supadart.
// WARNING: Modifications may be overwritten. Please make changes in the Supadart configuration.
import 'package:sigap/supadart/supadart_exports.dart';
import 'package:sigap/supadart/supadart_header.dart';

enum UNIT_TYPE { other, polda, polres, polsek }

class UnitSupadartModel implements SupadartClass<UnitSupadartModel> {
  final String codeUnit;
  final String? districtId;
  final String name;
  final String? description;
  final UNIT_TYPE type;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String? address;
  final double? landArea;
  final double latitude;
  final double longitude;
  final String location;
  final String cityId;
  final String? phone;
  final CitySupadartModel? city;
  final DistrictSupadartModel? district;

  const UnitSupadartModel({
    required this.codeUnit,
    this.districtId,
    required this.name,
    this.description,
    required this.type,
    this.createdAt,
    this.updatedAt,
    this.address,
    this.landArea,
    required this.latitude,
    required this.longitude,
    required this.location,
    required this.cityId,
    this.phone,
    this.city,
    this.district,
  });

  static String get table_name => 'unitSupadartModel';
  static String get c_codeUnit => 'code_unit';
  static String get c_districtId => 'district_id';
  static String get c_name => 'name';
  static String get c_description => 'description';
  static String get c_type => 'type';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';
  static String get c_address => 'address';
  static String get c_landArea => 'land_area';
  static String get c_latitude => 'latitude';
  static String get c_longitude => 'longitude';
  static String get c_location => 'location';
  static String get c_cityId => 'city_id';
  static String get c_phone => 'phone';

  static List<UnitSupadartModel> converter(List<Map<String, dynamic>> data) {
    return data.map(UnitSupadartModel.fromJson).toList();
  }

  static UnitSupadartModel converterSingle(Map<String, dynamic> data) {
    return UnitSupadartModel.fromJson(data);
  }

  static Map<String, dynamic> _generateMap({
    String? codeUnit,
    String? districtId,
    String? name,
    String? description,
    UNIT_TYPE? type,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? address,
    double? landArea,
    double? latitude,
    double? longitude,
    String? location,
    String? cityId,
    String? phone,
  }) {
    return {
      if (codeUnit != null) 'code_unit': codeUnit,
      if (districtId != null) 'district_id': districtId,
      if (name != null) 'name': name,
      if (description != null) 'description': description,
      if (type != null) 'type': type.toString().split('.').last,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (updatedAt != null) 'updated_at': updatedAt.toUtc().toIso8601String(),
      if (address != null) 'address': address,
      if (landArea != null) 'land_area': landArea.toString(),
      if (latitude != null) 'latitude': latitude.toString(),
      if (longitude != null) 'longitude': longitude.toString(),
      if (location != null) 'location': location,
      if (cityId != null) 'city_id': cityId,
      if (phone != null) 'phone': phone,
    };
  }

  static Map<String, dynamic> insert({
    String? codeUnit,
    String? districtId,
    required String name,
    String? description,
    required UNIT_TYPE type,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? address,
    double? landArea,
    required double latitude,
    required double longitude,
    required String location,
    required String cityId,
    String? phone,
  }) {
    return _generateMap(
      codeUnit: codeUnit,
      districtId: districtId,
      name: name,
      description: description,
      type: type,
      createdAt: createdAt,
      updatedAt: updatedAt,
      address: address,
      landArea: landArea,
      latitude: latitude,
      longitude: longitude,
      location: location,
      cityId: cityId,
      phone: phone,
    );
  }

  static Map<String, dynamic> update({
    String? codeUnit,
    String? districtId,
    String? name,
    String? description,
    UNIT_TYPE? type,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? address,
    double? landArea,
    double? latitude,
    double? longitude,
    String? location,
    String? cityId,
    String? phone,
  }) {
    return _generateMap(
      codeUnit: codeUnit,
      districtId: districtId,
      name: name,
      description: description,
      type: type,
      createdAt: createdAt,
      updatedAt: updatedAt,
      address: address,
      landArea: landArea,
      latitude: latitude,
      longitude: longitude,
      location: location,
      cityId: cityId,
      phone: phone,
    );
  }

  factory UnitSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return UnitSupadartModel(
      codeUnit: jsonn['code_unit'] != null ? jsonn['code_unit'].toString() : '',
      districtId:
          jsonn['district_id'] != null ? jsonn['district_id'].toString() : null,
      name: jsonn['name'] != null ? jsonn['name'].toString() : '',
      description:
          jsonn['description'] != null ? jsonn['description'].toString() : null,
      type:
          jsonn['type'] != null
              ? UNIT_TYPE.values.byName(jsonn['type'].toString())
              : UNIT_TYPE.values.first,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : null,
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].toString())
              : null,
      address: jsonn['address'] != null ? jsonn['address'].toString() : null,
      landArea:
          jsonn['land_area'] != null
              ? double.parse(jsonn['land_area'].toString())
              : null,
      latitude:
          jsonn['latitude'] != null
              ? double.parse(jsonn['latitude'].toString())
              : 0.0,
      longitude:
          jsonn['longitude'] != null
              ? double.parse(jsonn['longitude'].toString())
              : 0.0,
      location: jsonn['location'] != null ? jsonn['location'].toString() : '',
      cityId: jsonn['city_id'] != null ? jsonn['city_id'].toString() : '',
      phone: jsonn['phone'] != null ? jsonn['phone'].toString() : null,
      city:
          jsonn['cities'] != null
              ? CitySupadartModel.fromJson(
                jsonn['cities'] as Map<String, dynamic>,
              )
              : null,
      district:
          jsonn['districts'] != null
              ? DistrictSupadartModel.fromJson(
                jsonn['districts'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      codeUnit: codeUnit,
      districtId: districtId,
      name: name,
      description: description,
      type: type,
      createdAt: createdAt,
      updatedAt: updatedAt,
      address: address,
      landArea: landArea,
      latitude: latitude,
      longitude: longitude,
      location: location,
      cityId: cityId,
      phone: phone,
      // 'cities': city?.toJson(),
      // 'districts': district?.toJson(),
    );
  }

  static const _unset = Object();
  UnitSupadartModel copyWith({
    Object? codeUnit = _unset,
    Object? districtId = _unset,
    Object? name = _unset,
    Object? description = _unset,
    Object? type = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? address = _unset,
    Object? landArea = _unset,
    Object? latitude = _unset,
    Object? longitude = _unset,
    Object? location = _unset,
    Object? cityId = _unset,
    Object? phone = _unset,
    Object? city = _unset,
    Object? district = _unset,
  }) {
    return UnitSupadartModel(
      codeUnit: codeUnit == _unset ? this.codeUnit : codeUnit as String,
      districtId:
          districtId == _unset ? this.districtId : districtId as String?,
      name: name == _unset ? this.name : name as String,
      description:
          description == _unset ? this.description : description as String?,
      type: type == _unset ? this.type : type as UNIT_TYPE,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      address: address == _unset ? this.address : address as String?,
      landArea: landArea == _unset ? this.landArea : landArea as double?,
      latitude: latitude == _unset ? this.latitude : latitude as double,
      longitude: longitude == _unset ? this.longitude : longitude as double,
      location: location == _unset ? this.location : location as String,
      cityId: cityId == _unset ? this.cityId : cityId as String,
      phone: phone == _unset ? this.phone : phone as String?,
      city: city == _unset ? this.city : city as CitySupadartModel?,
      district:
          district == _unset
              ? this.district
              : district as DistrictSupadartModel?,
    );
  }
}
