// 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 LocationLogSupadartModel
    implements SupadartClass<LocationLogSupadartModel> {
  final String id;
  final String userId;
  final double latitude;
  final double longitude;
  final String location;
  final DateTime timestamp;
  final String? description;
  final DateTime createdAt;
  final DateTime updatedAt;
  final UserSupadartModel? user;

  const LocationLogSupadartModel({
    required this.id,
    required this.userId,
    required this.latitude,
    required this.longitude,
    required this.location,
    required this.timestamp,
    this.description,
    required this.createdAt,
    required this.updatedAt,
    this.user,
  });

  static String get table_name => 'location_logs';
  static String get c_id => 'id';
  static String get c_userId => 'user_id';
  static String get c_latitude => 'latitude';
  static String get c_longitude => 'longitude';
  static String get c_location => 'location';
  static String get c_timestamp => 'timestamp';
  static String get c_description => 'description';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? userId,
    double? latitude,
    double? longitude,
    String? location,
    DateTime? timestamp,
    String? description,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (userId != null) 'user_id': userId,
      if (latitude != null) 'latitude': latitude.toString(),
      if (longitude != null) 'longitude': longitude.toString(),
      if (location != null) 'location': location,
      if (timestamp != null) 'timestamp': timestamp.toUtc().toIso8601String(),
      if (description != null) 'description': description,
      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 userId,
    required double latitude,
    required double longitude,
    required String location,
    required DateTime timestamp,
    String? description,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      latitude: latitude,
      longitude: longitude,
      location: location,
      timestamp: timestamp,
      description: description,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? userId,
    double? latitude,
    double? longitude,
    String? location,
    DateTime? timestamp,
    String? description,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      latitude: latitude,
      longitude: longitude,
      location: location,
      timestamp: timestamp,
      description: description,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  factory LocationLogSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return LocationLogSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      userId: jsonn['user_id'] != null ? jsonn['user_id'].toString() : '',
      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() : '',
      timestamp:
          jsonn['timestamp'] != null
              ? DateTime.parse(jsonn['timestamp'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      description:
          jsonn['description'] != null ? jsonn['description'].toString() : null,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      user:
          jsonn['users'] != null
              ? UserSupadartModel.fromJson(
                jsonn['users'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      userId: userId,
      latitude: latitude,
      longitude: longitude,
      location: location,
      timestamp: timestamp,
      description: description,
      createdAt: createdAt,
      updatedAt: updatedAt,
      // 'users': user?.toJson(),
    );
  }

  static const _unset = Object();
  LocationLogSupadartModel copyWith({
    Object? id = _unset,
    Object? userId = _unset,
    Object? latitude = _unset,
    Object? longitude = _unset,
    Object? location = _unset,
    Object? timestamp = _unset,
    Object? description = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? user = _unset,
  }) {
    return LocationLogSupadartModel(
      id: id == _unset ? this.id : id as String,
      userId: userId == _unset ? this.userId : userId as String,
      latitude: latitude == _unset ? this.latitude : latitude as double,
      longitude: longitude == _unset ? this.longitude : longitude as double,
      location: location == _unset ? this.location : location as String,
      timestamp: timestamp == _unset ? this.timestamp : timestamp as DateTime,
      description:
          description == _unset ? this.description : description as String?,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime,
      user: user == _unset ? this.user : user as UserSupadartModel?,
    );
  }
}
