// Consolidated riders models

class RiderLog {
  int? logid;
  String? logdate;
  int? userid;
  int? partnerid;
  int? shiftid;
  double? shifthours;
  String? login;
  String? latitude;
  double? workhours;
  double? shorthours;
  int? logstatus;
  String? longitude;
  double? breakhours;

  int? onduty;
  int? tenantid;
  int? locationid;
  int? applocationid;
  String? userfcmtoken;

  RiderLog({
    this.logid,
    this.logdate,
    this.userid,
    this.partnerid,
    this.shiftid,
    this.shifthours,
    this.login,
    this.latitude,
    this.workhours,
    this.shorthours,
    this.logstatus,
    this.longitude,
    this.breakhours,
    this.onduty,
    this.tenantid,
    this.locationid,
    this.applocationid,
    this.userfcmtoken,
  });

  factory RiderLog.fromJson(Map<String, dynamic> json) {
    return RiderLog(
      logid: json['logid'],
      logdate: json['logdate'],
      userid: json['userid'],
      partnerid: json['partnerid'],
      shiftid: json['shiftid'],
      shifthours: (json['shifthours'] as num?)?.toDouble(),
      login: json['login'],
      latitude: json['latitude'],
      workhours: (json['workhours'] as num?)?.toDouble(),
      shorthours: (json['shorthours'] as num?)?.toDouble(),
      logstatus: json['logstatus'],
      longitude: json['longitude'],
      breakhours: (json['breakhours'] as num?)?.toDouble(),
      onduty: json['onduty'],
      tenantid: json['tenantid'],
      locationid: json['locationid'],
      applocationid: json['applocationid'],
      userfcmtoken: json['userfcmtoken'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['logid'] = logid;
    data['logdate'] = logdate;
    data['userid'] = userid;
    data['partnerid'] = partnerid;
    data['shiftid'] = shiftid;
    data['shifthours'] = shifthours;
    data['login'] = login;
    data['latitude'] = latitude;
    data['workhours'] = workhours;
    data['shorthours'] = shorthours;
    data['logstatus'] = logstatus;
    data['longitude'] = longitude;
    data['breakhours'] = breakhours;
    data['onduty'] = onduty;
    data['tenantid'] = tenantid;
    data['locationid'] = locationid;
    data['applocationid'] = applocationid;
    data['userfcmtoken'] = userfcmtoken;
    return data;
  }
}

class RiderBreak {
  int? breakid;
  int? logid;
  String? breakdate;
  int? userid;
  int? partnerid;
  int? shiftid;
  String? breakstart;
  String? breakend;
  double? breakhours;
  String? latitude;
  String? longitude;

  RiderBreak({
    this.breakid,
    this.logid,
    this.breakdate,
    this.userid,
    this.partnerid,
    this.shiftid,
    this.breakstart,
    this.breakend,
    this.breakhours,
    this.latitude,
    this.longitude,
  });

  factory RiderBreak.fromJson(Map<String, dynamic> json) {
    return RiderBreak(
      breakid: json['breakid'],
      logid: json['logid'],
      breakdate: json['breakdate'],
      userid: json['userid'],
      partnerid: json['partnerid'],
      shiftid: json['shiftid'],
      breakstart: json['breakstart'],
      breakend: json['breakend'],
      breakhours: (json['breakhours'] as num?)?.toDouble(),
      latitude: json['latitude'],
      longitude: json['longitude'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['breakid'] = breakid;
    data['logid'] = logid;
    data['breakdate'] = breakdate;
    data['userid'] = userid;
    data['partnerid'] = partnerid;
    data['shiftid'] = shiftid;
    data['breakstart'] = breakstart;
    data['breakend'] = breakend;
    data['breakhours'] = breakhours;
    data['latitude'] = latitude;
    data['longitude'] = longitude;
    return data;
  }
}

class RiderLogin {
  int? logid;
  int? userid;
  int? partnerid;
  int? shiftid;
  String? logdate;
  String? login;
  double? shifthours;
  String? latitude;
  String? longitude;
  int? onduty;
  String? status; // "active" when there are active deliveries, "idle" otherwise
  String? username; // Rider display name for rider logs
  String? contactno;
  int? tenantid;
  int? locationid;
  int? applocationid;
  String? userfcmtoken;

  RiderLogin({
    this.logid,
    this.userid,
    this.partnerid,
    this.shiftid,
    this.logdate,
    this.login,
    this.shifthours,
    this.latitude,
    this.longitude,
    this.onduty,
    this.status,
    this.username,

    this.contactno,
    this.tenantid,
    this.locationid,
    this.applocationid,
    this.userfcmtoken,
  });

  factory RiderLogin.fromJson(Map<String, dynamic> json) {
    return RiderLogin(
      logid: json['logid'],
      userid: json['userid'],
      partnerid: json['partnerid'],
      shiftid: json['shiftid'],
      logdate: json['logdate'],
      login: json['Login'] ?? json['login'],
      shifthours: (json['shifthours'] as num?)?.toDouble(),
      latitude: json['latitude'],
      longitude: json['longitude'],
      onduty: json['onduty'],
      status: json['status'],
      username: json['username'],
      contactno: json['contactno'],
      tenantid: json['tenantid'],
      locationid: json['locationid'],
      applocationid: json['applocationid'],
      userfcmtoken: json['userfcmtoken'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['logid'] = logid;
    data['userid'] = userid;
    data['partnerid'] = partnerid;
    data['shiftid'] = shiftid;
    data['logdate'] = logdate;
    data['Login'] = login;
    data['shifthours'] = shifthours;
    data['latitude'] = latitude;
    data['longitude'] = longitude;
    if (onduty != null) data['onduty'] = onduty;
    if (status != null) data['status'] = status;
    if (username != null && username!.trim().isNotEmpty) {
      data['username'] = username;
    }
    if (contactno != null) {
      data['contactno'] = contactno;
    }
    data['tenantid'] = tenantid;
    data['locationid'] = locationid;
    data['applocationid'] = applocationid;
    data['userfcmtoken'] = userfcmtoken;
    return data;
  }
}

class RiderUpdate {
  int? userid;
  int? logstatus;
  String? logout;
  double? workhours;
  double? shorthours;
  String? latitude;
  String? longitude;
  int? onduty;

  RiderUpdate({
    this.userid,
    this.logstatus,
    this.logout,
    this.workhours,
    this.shorthours,
    this.latitude,
    this.longitude,
    this.onduty,
  });

  factory RiderUpdate.fromJson(Map<String, dynamic> json) {
    return RiderUpdate(
      userid: json['userid'],
      logstatus: json['logstatus'],
      logout: json['Logout'] ?? json['logout'],
      workhours: (json['workhours'] as num?)?.toDouble(),
      shorthours: (json['shorthours'] as num?)?.toDouble(),
      latitude: json['latitude'],
      longitude: json['longitude'],
      onduty: json['onduty'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['userid'] = userid;
    data['logstatus'] = logstatus;
    data['Logout'] = logout;
    data['workhours'] = workhours;
    data['shorthours'] = shorthours;
    data['latitude'] = latitude;
    data['longitude'] = longitude;
    if (onduty != null) data['onduty'] = onduty;
    return data;
  }
}


