// 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_header.dart';

class Logs implements SupadartClass<Logs> {
  final String id;
  final String action;
  final String entity;
  final String? entityId;
  final Map<String, dynamic>? changes;
  final String? userId;
  final String? ipAddress;
  final String? userAgent;
  final DateTime createdAt;

  const Logs({
    required this.id,
    required this.action,
    required this.entity,
    this.entityId,
    this.changes,
    this.userId,
    this.ipAddress,
    this.userAgent,
    required this.createdAt,
  });

  static String get table_name => 'logs';
  static String get c_id => 'id';
  static String get c_action => 'action';
  static String get c_entity => 'entity';
  static String get c_entityId => 'entity_id';
  static String get c_changes => 'changes';
  static String get c_userId => 'user_id';
  static String get c_ipAddress => 'ip_address';
  static String get c_userAgent => 'user_agent';
  static String get c_createdAt => 'created_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? action,
    String? entity,
    String? entityId,
    Map<String, dynamic>? changes,
    String? userId,
    String? ipAddress,
    String? userAgent,
    DateTime? createdAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (action != null) 'action': action,
      if (entity != null) 'entity': entity,
      if (entityId != null) 'entity_id': entityId,
      if (changes != null) 'changes': changes,
      if (userId != null) 'user_id': userId,
      if (ipAddress != null) 'ip_address': ipAddress,
      if (userAgent != null) 'user_agent': userAgent,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String action,
    required String entity,
    String? entityId,
    Map<String, dynamic>? changes,
    String? userId,
    String? ipAddress,
    String? userAgent,
    DateTime? createdAt,
  }) {
    return _generateMap(
      id: id,
      action: action,
      entity: entity,
      entityId: entityId,
      changes: changes,
      userId: userId,
      ipAddress: ipAddress,
      userAgent: userAgent,
      createdAt: createdAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? action,
    String? entity,
    String? entityId,
    Map<String, dynamic>? changes,
    String? userId,
    String? ipAddress,
    String? userAgent,
    DateTime? createdAt,
  }) {
    return _generateMap(
      id: id,
      action: action,
      entity: entity,
      entityId: entityId,
      changes: changes,
      userId: userId,
      ipAddress: ipAddress,
      userAgent: userAgent,
      createdAt: createdAt,
    );
  }

  factory Logs.fromJson(Map<String, dynamic> jsonn) {
    return Logs(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      action: jsonn['action'] != null ? jsonn['action'].toString() : '',
      entity: jsonn['entity'] != null ? jsonn['entity'].toString() : '',
      entityId:
          jsonn['entity_id'] != null ? jsonn['entity_id'].toString() : null,
      changes:
          jsonn['changes'] != null
              ? jsonn['changes'] as Map<String, dynamic>
              : null,
      userId: jsonn['user_id'] != null ? jsonn['user_id'].toString() : null,
      ipAddress:
          jsonn['ip_address'] != null ? jsonn['ip_address'].toString() : null,
      userAgent:
          jsonn['user_agent'] != null ? jsonn['user_agent'].toString() : null,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      action: action,
      entity: entity,
      entityId: entityId,
      changes: changes,
      userId: userId,
      ipAddress: ipAddress,
      userAgent: userAgent,
      createdAt: createdAt,
    );
  }

  static const _unset = Object();
  Logs copyWith({
    Object? id = _unset,
    Object? action = _unset,
    Object? entity = _unset,
    Object? entityId = _unset,
    Object? changes = _unset,
    Object? userId = _unset,
    Object? ipAddress = _unset,
    Object? userAgent = _unset,
    Object? createdAt = _unset,
  }) {
    return Logs(
      id: id == _unset ? this.id : id as String,
      action: action == _unset ? this.action : action as String,
      entity: entity == _unset ? this.entity : entity as String,
      entityId: entityId == _unset ? this.entityId : entityId as String?,
      changes:
          changes == _unset ? this.changes : changes as Map<String, dynamic>?,
      userId: userId == _unset ? this.userId : userId as String?,
      ipAddress: ipAddress == _unset ? this.ipAddress : ipAddress as String?,
      userAgent: userAgent == _unset ? this.userAgent : userAgent as String?,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime,
    );
  }
}
