// 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';

class DistrictSupadartModel implements SupadartClass<DistrictSupadartModel> {
  final String id;
  final String cityId;
  final String name;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final CitySupadartModel? city;

  const DistrictSupadartModel({
    required this.id,
    required this.cityId,
    required this.name,
    this.createdAt,
    this.updatedAt,
    this.city,
  });

  static String get table_name => 'districtSupadartModel';
  static String get c_id => 'id';
  static String get c_cityId => 'city_id';
  static String get c_name => 'name';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? cityId,
    String? name,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (cityId != null) 'city_id': cityId,
      if (name != null) 'name': name,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (updatedAt != null) 'updated_at': updatedAt.toUtc().toIso8601String(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String cityId,
    required String name,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      cityId: cityId,
      name: name,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? cityId,
    String? name,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      cityId: cityId,
      name: name,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  factory DistrictSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return DistrictSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      cityId: jsonn['city_id'] != null ? jsonn['city_id'].toString() : '',
      name: jsonn['name'] != null ? jsonn['name'].toString() : '',
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : null,
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].toString())
              : null,
      city:
          jsonn['cities'] != null
              ? CitySupadartModel.fromJson(
                jsonn['cities'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      cityId: cityId,
      name: name,
      createdAt: createdAt,
      updatedAt: updatedAt,
      // 'cities': city?.toJson(),
    );
  }

  static const _unset = Object();
  DistrictSupadartModel copyWith({
    Object? id = _unset,
    Object? cityId = _unset,
    Object? name = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? city = _unset,
  }) {
    return DistrictSupadartModel(
      id: id == _unset ? this.id : id as String,
      cityId: cityId == _unset ? this.cityId : cityId as String,
      name: name == _unset ? this.name : name as String,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      city: city == _unset ? this.city : city as CitySupadartModel?,
    );
  }
}
