// 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 PatrolUnitSupadartModel
    implements SupadartClass<PatrolUnitSupadartModel> {
  final String unitId;
  final String locationId;
  final String name;
  final String type;
  final String status;
  final double radius;
  final DateTime createdAt;
  final String id;
  final LocationSupadartModel? location;
  final UnitSupadartModel? unit;

  const PatrolUnitSupadartModel({
    required this.unitId,
    required this.locationId,
    required this.name,
    required this.type,
    required this.status,
    required this.radius,
    required this.createdAt,
    required this.id,
    this.location,
    this.unit,
  });

  static String get table_name => 'patrol_units';
  static String get c_unitId => 'unit_id';
  static String get c_locationId => 'location_id';
  static String get c_name => 'name';
  static String get c_type => 'type';
  static String get c_status => 'status';
  static String get c_radius => 'radius';
  static String get c_createdAt => 'created_at';
  static String get c_id => 'id';

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

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

  static Map<String, dynamic> _generateMap({
    String? unitId,
    String? locationId,
    String? name,
    String? type,
    String? status,
    double? radius,
    DateTime? createdAt,
    String? id,
  }) {
    return {
      if (unitId != null) 'unit_id': unitId,
      if (locationId != null) 'location_id': locationId,
      if (name != null) 'name': name,
      if (type != null) 'type': type,
      if (status != null) 'status': status,
      if (radius != null) 'radius': radius.toString(),
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (id != null) 'id': id,
    };
  }

  static Map<String, dynamic> insert({
    required String unitId,
    required String locationId,
    required String name,
    required String type,
    required String status,
    required double radius,
    DateTime? createdAt,
    String? id,
  }) {
    return _generateMap(
      unitId: unitId,
      locationId: locationId,
      name: name,
      type: type,
      status: status,
      radius: radius,
      createdAt: createdAt,
      id: id,
    );
  }

  static Map<String, dynamic> update({
    String? unitId,
    String? locationId,
    String? name,
    String? type,
    String? status,
    double? radius,
    DateTime? createdAt,
    String? id,
  }) {
    return _generateMap(
      unitId: unitId,
      locationId: locationId,
      name: name,
      type: type,
      status: status,
      radius: radius,
      createdAt: createdAt,
      id: id,
    );
  }

  factory PatrolUnitSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return PatrolUnitSupadartModel(
      unitId: jsonn['unit_id'] != null ? jsonn['unit_id'].toString() : '',
      locationId:
          jsonn['location_id'] != null ? jsonn['location_id'].toString() : '',
      name: jsonn['name'] != null ? jsonn['name'].toString() : '',
      type: jsonn['type'] != null ? jsonn['type'].toString() : '',
      status: jsonn['status'] != null ? jsonn['status'].toString() : '',
      radius:
          jsonn['radius'] != null
              ? double.parse(jsonn['radius'].toString())
              : 0.0,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      location:
          jsonn['locations'] != null
              ? LocationSupadartModel.fromJson(
                jsonn['locations'] as Map<String, dynamic>,
              )
              : null,
      unit:
          jsonn['unitSupadartModel'] != null
              ? UnitSupadartModel.fromJson(
                jsonn['unitSupadartModel'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      unitId: unitId,
      locationId: locationId,
      name: name,
      type: type,
      status: status,
      radius: radius,
      createdAt: createdAt,
      id: id,
      // 'locations': location?.toJson(),
      // 'unitSupadartModel': unit?.toJson(),
    );
  }

  static const _unset = Object();
  PatrolUnitSupadartModel copyWith({
    Object? unitId = _unset,
    Object? locationId = _unset,
    Object? name = _unset,
    Object? type = _unset,
    Object? status = _unset,
    Object? radius = _unset,
    Object? createdAt = _unset,
    Object? id = _unset,
    Object? location = _unset,
    Object? unit = _unset,
  }) {
    return PatrolUnitSupadartModel(
      unitId: unitId == _unset ? this.unitId : unitId as String,
      locationId: locationId == _unset ? this.locationId : locationId as String,
      name: name == _unset ? this.name : name as String,
      type: type == _unset ? this.type : type as String,
      status: status == _unset ? this.status : status as String,
      radius: radius == _unset ? this.radius : radius as double,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime,
      id: id == _unset ? this.id : id as String,
      location:
          location == _unset
              ? this.location
              : location as LocationSupadartModel?,
      unit: unit == _unset ? this.unit : unit as UnitSupadartModel?,
    );
  }
}
