// 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 ResourceSupadartModel implements SupadartClass<ResourceSupadartModel> {
  final String id;
  final String name;
  final String? type;
  final String? description;
  final String? instanceRole;
  final String? relations;
  final Map<String, dynamic>? attributes;
  final DateTime createdAt;
  final DateTime updatedAt;

  const ResourceSupadartModel({
    required this.id,
    required this.name,
    this.type,
    this.description,
    this.instanceRole,
    this.relations,
    this.attributes,
    required this.createdAt,
    required this.updatedAt,
  });

  static String get table_name => 'resourceSupadartModel';
  static String get c_id => 'id';
  static String get c_name => 'name';
  static String get c_type => 'type';
  static String get c_description => 'description';
  static String get c_instanceRole => 'instance_role';
  static String get c_relations => 'relations';
  static String get c_attributes => 'attributes';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? name,
    String? type,
    String? description,
    String? instanceRole,
    String? relations,
    Map<String, dynamic>? attributes,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (name != null) 'name': name,
      if (type != null) 'type': type,
      if (description != null) 'description': description,
      if (instanceRole != null) 'instance_role': instanceRole,
      if (relations != null) 'relations': relations,
      if (attributes != null) 'attributes': attributes,
      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 name,
    String? type,
    String? description,
    String? instanceRole,
    String? relations,
    Map<String, dynamic>? attributes,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      name: name,
      type: type,
      description: description,
      instanceRole: instanceRole,
      relations: relations,
      attributes: attributes,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? name,
    String? type,
    String? description,
    String? instanceRole,
    String? relations,
    Map<String, dynamic>? attributes,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      name: name,
      type: type,
      description: description,
      instanceRole: instanceRole,
      relations: relations,
      attributes: attributes,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  factory ResourceSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return ResourceSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      name: jsonn['name'] != null ? jsonn['name'].toString() : '',
      type: jsonn['type'] != null ? jsonn['type'].toString() : null,
      description:
          jsonn['description'] != null ? jsonn['description'].toString() : null,
      instanceRole:
          jsonn['instance_role'] != null
              ? jsonn['instance_role'].toString()
              : null,
      relations:
          jsonn['relations'] != null ? jsonn['relations'].toString() : null,
      attributes:
          jsonn['attributes'] != null
              ? jsonn['attributes'] as Map<String, dynamic>
              : 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),
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      name: name,
      type: type,
      description: description,
      instanceRole: instanceRole,
      relations: relations,
      attributes: attributes,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  static const _unset = Object();
  ResourceSupadartModel copyWith({
    Object? id = _unset,
    Object? name = _unset,
    Object? type = _unset,
    Object? description = _unset,
    Object? instanceRole = _unset,
    Object? relations = _unset,
    Object? attributes = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
  }) {
    return ResourceSupadartModel(
      id: id == _unset ? this.id : id as String,
      name: name == _unset ? this.name : name as String,
      type: type == _unset ? this.type : type as String?,
      description:
          description == _unset ? this.description : description as String?,
      instanceRole:
          instanceRole == _unset ? this.instanceRole : instanceRole as String?,
      relations: relations == _unset ? this.relations : relations as String?,
      attributes:
          attributes == _unset
              ? this.attributes
              : attributes as Map<String, dynamic>?,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime,
    );
  }
}
