import 'package:flutter/material.dart';

class Condition {
  String? conditionCode;
  String? conditionName;

  Condition();

  Condition.fromJson(Map<String, dynamic> json) {
    conditionCode = json['conditionCode'];
    conditionName = json['conditionName'];
  }

  Map<String, dynamic> toJson() {
    return {
      'conditionCode': conditionCode,
      'conditionName': conditionName,
    };
  }
}

class Category {
  int? categoryId;
  String? code;
  String? codeAlias;
  List<Condition>? conditionsList;
  String? description;
  String? descriptionAlias;
  int? id;
  bool? isActive;
  bool? isBuiltin;
  String? languageCode;
  String? name;
  String? nameAlias;
  int? rowVersion;
  int? specialityId;
  String? specialityName;
  List<dynamic>? translationValues;
  bool isSelected = false;
  TextEditingController remarksController = TextEditingController();
  int selectedCondition = -1;
  String selectedConditionName = "";
  String? pomrId;
  int? paitientId;
  int? userID;
  bool isExpanded = false;

  Category();

  Category.fromJson(Map<String, dynamic> json,int? specialityId, String specialityName, String? pomrId, int paitientId, int userID) {
    categoryId = json['categoryId'];
    code = json['code'];
    codeAlias = json['codeAlias'];
    if (json['conditionsList'] != null) {
      conditionsList = <Condition>[];
      json['conditionsList'].forEach((v) {
        conditionsList!.add(Condition.fromJson(v));
      });
    }
    if(conditionsList?.isNotEmpty == true)  selectedCondition = int.parse(conditionsList?.first.conditionName ??'-1');
    description = json['description'];
    descriptionAlias = json['descriptionAlias'];
    id = json['id'];
    isActive = json['isActive'];
    isBuiltin = json['isBuiltin'];
    languageCode = json['languageCode'];
    name = json['name'];
    nameAlias = json['nameAlias'];
    rowVersion = json['rowVersion'];
    translationValues = json['translationValues'];
    this.specialityName = specialityName;
    this.specialityId = specialityId;
    this.pomrId = pomrId;
    this.paitientId = paitientId;
    this.userID = userID;
  }

  Map<String, dynamic> toJson() {
    return {
      'categoryId': categoryId,
      'code': code,
      'codeAlias': codeAlias,
      'conditionsList': conditionsList?.map((v) => v.toJson()).toList(),
      'description': description,
      'descriptionAlias': descriptionAlias,
      'id': id,
      'isActive': isActive,
      'isBuiltin': isBuiltin,
      'languageCode': languageCode,
      'name': name,
      'nameAlias': nameAlias,
      'rowVersion': rowVersion,
      'translationValues': translationValues,
    };
  }
}