import 'package:objectbox/objectbox.dart';
import 'package:mobdr/objectbox.g.dart';
import 'package:mobdr/config/constant.dart';

// ignore_for_file: public_member_api_docs

@Entity()
class Visit {
  // specify the id
  @Id()
  int id = 0;

  int id_visite;
  DateTime date_visite;
  DateTime date_debut;
  DateTime? date_fin;
  DateTime? date_validation;
  String type_visite;
  String title;
  bool allDay;
  int id_distrib_visite;
  int id_etab;
  int abandon;
  String url_photo_principale;
  String langage;

  Visit(
      {this.id = 0,
      required this.id_visite,
      required this.date_visite,
      required this.date_debut,
      required this.date_fin,
      required this.date_validation,
      required this.type_visite,
      required this.title,
      required this.allDay,
      required this.id_distrib_visite,
      required this.id_etab,
      required this.abandon,
      required this.url_photo_principale,
      required this.langage});

  Visit.fromJson(Map<String, dynamic> json)
      : id_visite = json['id_visite'],
        date_visite = DateTime.parse(json['start']),
        date_debut = DateTime.parse(json['start']),
        date_fin = json['end'].isNotEmpty ? DateTime.parse(json['end']) : null,
        date_validation = json['validation'].isNotEmpty
            ? DateTime.parse(json['validation'])
            : null,
        type_visite = json['type_visite'],
        title = json['title'],
        allDay = json['allDay'],
        id_distrib_visite = json['id_distrib_visite'],
        id_etab = json['id_etab'],
        abandon = json['abandon'],
        url_photo_principale =
            ApiConstants.baseUrl + json['url_photo_principale'],
        langage = 'fr';
}
