import 'package:json_annotation/json_annotation.dart';
import '../../domain/entities/type_reference_entity.dart';

part 'type_reference_model.g.dart';

@JsonSerializable()
class TypeReferenceModel {
  final String id;
  final String domaine;
  final String code;
  final String libelle;
  final String? description;
  final String? icone;
  final String? couleur;
  final String? severity;
  @JsonKey(defaultValue: 0)
  final int ordreAffichage;
  @JsonKey(defaultValue: false)
  final bool estDefaut;
  @JsonKey(defaultValue: false)
  final bool estSysteme;
  @JsonKey(defaultValue: true)
  final bool actif;

  const TypeReferenceModel({
    required this.id,
    required this.domaine,
    required this.code,
    required this.libelle,
    this.description,
    this.icone,
    this.couleur,
    this.severity,
    this.ordreAffichage = 0,
    this.estDefaut = false,
    this.estSysteme = false,
    this.actif = true,
  });

  factory TypeReferenceModel.fromJson(Map<String, dynamic> json) =>
      _$TypeReferenceModelFromJson(json);

  Map<String, dynamic> toJson() => _$TypeReferenceModelToJson(this);

  TypeReferenceEntity toEntity() => TypeReferenceEntity(
    id: id,
    domaine: domaine,
    code: code,
    libelle: libelle,
    description: description,
    icone: icone,
    couleur: couleur,
    severity: severity,
    ordreAffichage: ordreAffichage,
    estDefaut: estDefaut,
    estSysteme: estSysteme,
    actif: actif,
  );

  factory TypeReferenceModel.fromEntity(TypeReferenceEntity entity) =>
      TypeReferenceModel(
        id: entity.id,
        domaine: entity.domaine,
        code: entity.code,
        libelle: entity.libelle,
        description: entity.description,
        icone: entity.icone,
        couleur: entity.couleur,
        severity: entity.severity,
        ordreAffichage: entity.ordreAffichage,
        estDefaut: entity.estDefaut,
        estSysteme: entity.estSysteme,
        actif: entity.actif,
      );
}
