/// 舱详情接口响应模型
///
/// 接口：GET /cabin/detail?carbinSn=xxx
/// 来源：从 laki_biz_app 拷贝并适配为本项目手写 fromJson 风格

class CabinDetailResponse {
  final String? pageTitle;
  final int? deviceId;
  final String? deviceName;
  final int? cabinId;
  final String? cabinName;
  final String? cabinType;
  final String? carbinSn;
  final String? cameraSn;
  final String? wifiPwd;
  final String? wifiName;
  final PetInfoResponse? petInfo;
  final CameraInfoResponse? cameraInfo;
  final MonitoringDataResponse? monitoringData;
  final CabinControlsResponse? cabinControls;
  final int? currentPlanId;
  final int? currentPetId;
  final String? status; // 舱状态
  final String? state; // 舱位物理状态

  CabinDetailResponse({
    this.pageTitle,
    this.deviceId,
    this.deviceName,
    this.cabinId,
    this.cabinName,
    this.cabinType,
    this.carbinSn,
    this.cameraSn,
    this.wifiPwd,
    this.wifiName,
    this.petInfo,
    this.cameraInfo,
    this.monitoringData,
    this.cabinControls,
    this.currentPlanId,
    this.currentPetId,
    this.status,
    this.state,
  });

  factory CabinDetailResponse.fromJson(Map<String, dynamic> json) {
    return CabinDetailResponse(
      pageTitle: json['pageTitle'] as String?,
      deviceId: json['deviceId'] as int?,
      deviceName: json['deviceName'] as String?,
      cabinId: json['cabinId'] as int?,
      cabinName: json['cabinName'] as String?,
      cabinType: json['cabinType'] as String?,
      carbinSn: json['carbinSn'] as String?,
      cameraSn: json['cameraSn'] as String?,
      wifiPwd: json['wifiPwd'] as String?,
      wifiName: json['wifiName'] as String?,
      petInfo: json['petInfo'] != null
          ? PetInfoResponse.fromJson(json['petInfo'] as Map<String, dynamic>)
          : null,
      cameraInfo: json['cameraInfo'] != null
          ? CameraInfoResponse.fromJson(
              json['cameraInfo'] as Map<String, dynamic>)
          : null,
      monitoringData: json['monitoringData'] != null
          ? MonitoringDataResponse.fromJson(
              json['monitoringData'] as Map<String, dynamic>)
          : null,
      cabinControls: json['cabinControls'] != null
          ? CabinControlsResponse.fromJson(
              json['cabinControls'] as Map<String, dynamic>)
          : null,
      currentPlanId: json['currentPlanId'] as int?,
      currentPetId: json['currentPetId'] as int?,
      status: json['status'] as String?,
      state: json['state'] as String?,
    );
  }

  CabinDetailResponse copyWith({
    String? pageTitle,
    int? deviceId,
    String? deviceName,
    int? cabinId,
    String? cabinName,
    String? cabinType,
    String? carbinSn,
    String? cameraSn,
    String? wifiPwd,
    String? wifiName,
    PetInfoResponse? petInfo,
    CameraInfoResponse? cameraInfo,
    MonitoringDataResponse? monitoringData,
    CabinControlsResponse? cabinControls,
    int? currentPlanId,
    int? currentPetId,
    String? status,
    String? state,
  }) {
    return CabinDetailResponse(
      pageTitle: pageTitle ?? this.pageTitle,
      deviceId: deviceId ?? this.deviceId,
      deviceName: deviceName ?? this.deviceName,
      cabinId: cabinId ?? this.cabinId,
      cabinName: cabinName ?? this.cabinName,
      cabinType: cabinType ?? this.cabinType,
      carbinSn: carbinSn ?? this.carbinSn,
      cameraSn: cameraSn ?? this.cameraSn,
      wifiPwd: wifiPwd ?? this.wifiPwd,
      wifiName: wifiName ?? this.wifiName,
      petInfo: petInfo ?? this.petInfo,
      cameraInfo: cameraInfo ?? this.cameraInfo,
      monitoringData: monitoringData ?? this.monitoringData,
      cabinControls: cabinControls ?? this.cabinControls,
      currentPlanId: currentPlanId ?? this.currentPlanId,
      currentPetId: currentPetId ?? this.currentPetId,
      status: status ?? this.status,
      state: state ?? this.state,
    );
  }
}

/// 宠物信息（舱详情接口子模型）
class PetInfoResponse {
  final int? petId;
  final String? name;
  final String? avatar;
  final String? type;
  final String? breedTag;
  final String? disease;
  final String? ownerName;
  final String? ownerPhone;
  final String? basicInfo;
  final String? petName;
  final String? petType;
  final String? monitoringStatus;

  PetInfoResponse({
    this.petId,
    this.name,
    this.avatar,
    this.type,
    this.breedTag,
    this.disease,
    this.ownerName,
    this.ownerPhone,
    this.basicInfo,
    this.petName,
    this.petType,
    this.monitoringStatus,
  });

  factory PetInfoResponse.fromJson(Map<String, dynamic> json) {
    return PetInfoResponse(
      petId: json['petId'] as int?,
      name: json['name'] as String?,
      avatar: json['avatar'] as String?,
      type: json['type'] as String?,
      breedTag: json['breedTag'] as String?,
      disease: json['disease'] as String?,
      ownerName: json['ownerName'] as String?,
      ownerPhone: json['ownerPhone'] as String?,
      basicInfo: json['basicInfo'] as String?,
      petName: json['petName'] as String?,
      petType: json['petType'] as String?,
      monitoringStatus: json['monitoringStatus'] as String?,
    );
  }

  PetInfoResponse copyWith({
    int? petId,
    String? name,
    String? avatar,
    String? type,
    String? breedTag,
    String? disease,
    String? ownerName,
    String? ownerPhone,
    String? basicInfo,
    String? petName,
    String? petType,
    String? monitoringStatus,
  }) {
    return PetInfoResponse(
      petId: petId ?? this.petId,
      name: name ?? this.name,
      avatar: avatar ?? this.avatar,
      type: type ?? this.type,
      breedTag: breedTag ?? this.breedTag,
      disease: disease ?? this.disease,
      ownerName: ownerName ?? this.ownerName,
      ownerPhone: ownerPhone ?? this.ownerPhone,
      basicInfo: basicInfo ?? this.basicInfo,
      petName: petName ?? this.petName,
      petType: petType ?? this.petType,
      monitoringStatus: monitoringStatus ?? this.monitoringStatus,
    );
  }
}

/// 摄像头信息（舱详情接口子模型）
class CameraInfoResponse {
  final int? cameraId;
  final String? cameraName;
  final String? sn;
  final String? cameraPwd;
  final String? status;
  final String? streamUrl;

  CameraInfoResponse({
    this.cameraId,
    this.cameraName,
    this.sn,
    this.cameraPwd,
    this.status,
    this.streamUrl,
  });

  factory CameraInfoResponse.fromJson(Map<String, dynamic> json) {
    return CameraInfoResponse(
      cameraId: json['cameraId'] as int?,
      cameraName: json['cameraName'] as String?,
      sn: json['sn'] as String?,
      cameraPwd: json['cameraPwd'] as String?,
      status: json['status'] as String?,
      streamUrl: json['streamUrl'] as String?,
    );
  }

  CameraInfoResponse copyWith({
    int? cameraId,
    String? cameraName,
    String? sn,
    String? cameraPwd,
    String? status,
    String? streamUrl,
  }) {
    return CameraInfoResponse(
      cameraId: cameraId ?? this.cameraId,
      cameraName: cameraName ?? this.cameraName,
      sn: sn ?? this.sn,
      cameraPwd: cameraPwd ?? this.cameraPwd,
      status: status ?? this.status,
      streamUrl: streamUrl ?? this.streamUrl,
    );
  }
}

/// 监控数据（舱详情接口子模型）
class MonitoringDataResponse {
  final int? totalDuration;
  final int? elapsedDuration;
  final String? status;
  final String? careLevel;
  final int? planId;
  final String? planName;
  final String? planType;
  final int? temperatureSetting;
  final int? mainTemperature;
  final int? humidity;
  final int? humiditySetting;
  final int? oxygenConcentration;
  final int? oxygenSetting;
  final int? openO2;
  final int? noOpenO2SettingMax;
  final int? openO2SettingMax;
  final int? co2Measurement;
  final int? co2Setting;
  final int? co2FastClearSwitch;
  final int? internalExternalCycleState;
  final int? floodLight;
  final int? inspectionLamp;
  final int? blueLight;
  final int? redLight;
  final int? airConditioner;
  final int? levelLight;
  final int? windSet;
  final int? rightAtomizerTreatmentTime;
  final int? rightInfraredPhysiotherapyTime;
  final int? wifible;
  final int? totalTime;
  final int? temperatureAlarm;
  final int? humidityAlarm;
  final int? oxygenAlarm;
  final int? co2Alarm;

  MonitoringDataResponse({
    this.totalDuration,
    this.elapsedDuration,
    this.status,
    this.careLevel,
    this.planId,
    this.planName,
    this.planType,
    this.temperatureSetting,
    this.mainTemperature,
    this.humidity,
    this.humiditySetting,
    this.oxygenConcentration,
    this.oxygenSetting,
    this.openO2,
    this.noOpenO2SettingMax,
    this.openO2SettingMax,
    this.co2Measurement,
    this.co2Setting,
    this.co2FastClearSwitch,
    this.internalExternalCycleState,
    this.floodLight,
    this.inspectionLamp,
    this.blueLight,
    this.redLight,
    this.airConditioner,
    this.levelLight,
    this.windSet,
    this.rightAtomizerTreatmentTime,
    this.rightInfraredPhysiotherapyTime,
    this.wifible,
    this.totalTime,
    this.temperatureAlarm,
    this.humidityAlarm,
    this.oxygenAlarm,
    this.co2Alarm,
  });

  factory MonitoringDataResponse.fromJson(Map<String, dynamic> json) {
    return MonitoringDataResponse(
      totalDuration: json['totalDuration'] as int?,
      elapsedDuration: json['elapsedDuration'] as int?,
      status: json['status'] as String?,
      careLevel: json['careLevel'] as String?,
      planId: json['planId'] as int?,
      planName: json['planName'] as String?,
      planType: json['planType'] as String?,
      temperatureSetting: json['temperatureSetting'] as int?,
      mainTemperature: json['mainTemperature'] as int?,
      humidity: json['humidity'] as int?,
      humiditySetting: json['humiditySetting'] as int?,
      oxygenConcentration: json['oxygenConcentration'] as int?,
      oxygenSetting: json['oxygenSetting'] as int?,
      openO2: json['openO2'] as int?,
      noOpenO2SettingMax: json['noOpenO2SettingMax'] as int?,
      openO2SettingMax: json['openO2SettingMax'] as int?,
      co2Measurement: json['co2Measurement'] as int?,
      co2Setting: json['co2Setting'] as int?,
      co2FastClearSwitch: json['co2FastClearSwitch'] as int?,
      internalExternalCycleState: json['internalExternalCycleState'] as int?,
      floodLight: json['floodLight'] as int?,
      inspectionLamp: json['inspectionLamp'] as int?,
      blueLight: json['blueLight'] as int?,
      redLight: json['redLight'] as int?,
      airConditioner: json['airConditioner'] as int?,
      levelLight: json['levelLight'] as int?,
      windSet: json['windSet'] as int?,
      rightAtomizerTreatmentTime: json['rightAtomizerTreatmentTime'] as int?,
      rightInfraredPhysiotherapyTime: json['rightInfraredPhysiotherapyTime'] as int?,
      wifible: json['wifible'] as int?,
      totalTime: json['totalTime'] as int?,
      temperatureAlarm: json['temperatureAlarm'] as int?,
      humidityAlarm: json['humidityAlarm'] as int?,
      oxygenAlarm: json['oxygenAlarm'] as int?,
      co2Alarm: json['co2Alarm'] as int?,
    );
  }

  MonitoringDataResponse copyWith({
    int? totalDuration,
    int? elapsedDuration,
    String? status,
    String? careLevel,
    int? planId,
    String? planName,
    String? planType,
    int? temperatureSetting,
    int? mainTemperature,
    int? humidity,
    int? humiditySetting,
    int? oxygenConcentration,
    int? oxygenSetting,
    int? openO2,
    int? noOpenO2SettingMax,
    int? openO2SettingMax,
    int? co2Measurement,
    int? co2Setting,
    int? co2FastClearSwitch,
    int? internalExternalCycleState,
    int? floodLight,
    int? inspectionLamp,
    int? blueLight,
    int? redLight,
    int? airConditioner,
    int? levelLight,
    int? windSet,
    int? rightAtomizerTreatmentTime,
    int? rightInfraredPhysiotherapyTime,
    int? wifible,
    int? totalTime,
    int? temperatureAlarm,
    int? humidityAlarm,
    int? oxygenAlarm,
    int? co2Alarm,
  }) {
    return MonitoringDataResponse(
      totalDuration: totalDuration ?? this.totalDuration,
      elapsedDuration: elapsedDuration ?? this.elapsedDuration,
      status: status ?? this.status,
      careLevel: careLevel ?? this.careLevel,
      planId: planId ?? this.planId,
      planName: planName ?? this.planName,
      planType: planType ?? this.planType,
      temperatureSetting: temperatureSetting ?? this.temperatureSetting,
      mainTemperature: mainTemperature ?? this.mainTemperature,
      humidity: humidity ?? this.humidity,
      humiditySetting: humiditySetting ?? this.humiditySetting,
      oxygenConcentration: oxygenConcentration ?? this.oxygenConcentration,
      oxygenSetting: oxygenSetting ?? this.oxygenSetting,
      openO2: openO2 ?? this.openO2,
      noOpenO2SettingMax: noOpenO2SettingMax ?? this.noOpenO2SettingMax,
      openO2SettingMax: openO2SettingMax ?? this.openO2SettingMax,
      co2Measurement: co2Measurement ?? this.co2Measurement,
      co2Setting: co2Setting ?? this.co2Setting,
      co2FastClearSwitch: co2FastClearSwitch ?? this.co2FastClearSwitch,
      internalExternalCycleState: internalExternalCycleState ?? this.internalExternalCycleState,
      floodLight: floodLight ?? this.floodLight,
      inspectionLamp: inspectionLamp ?? this.inspectionLamp,
      blueLight: blueLight ?? this.blueLight,
      redLight: redLight ?? this.redLight,
      airConditioner: airConditioner ?? this.airConditioner,
      levelLight: levelLight ?? this.levelLight,
      windSet: windSet ?? this.windSet,
      rightAtomizerTreatmentTime: rightAtomizerTreatmentTime ?? this.rightAtomizerTreatmentTime,
      rightInfraredPhysiotherapyTime: rightInfraredPhysiotherapyTime ?? this.rightInfraredPhysiotherapyTime,
      wifible: wifible ?? this.wifible,
      totalTime: totalTime ?? this.totalTime,
      temperatureAlarm: temperatureAlarm ?? this.temperatureAlarm,
      humidityAlarm: humidityAlarm ?? this.humidityAlarm,
      oxygenAlarm: oxygenAlarm ?? this.oxygenAlarm,
      co2Alarm: co2Alarm ?? this.co2Alarm,
    );
  }
}

/// 舱控制参数（舱详情接口子模型）
class CabinControlsResponse {
  final double? temperature;
  final double? oxygen;
  final double? humidity;
  final double? co2;
  final int? nebulizer;
  final int? sterilize;
  final String? fanMode;
  final String? airMode;
  final bool? newFan;
  final bool? openOxygen;
  final bool? checkLight;
  final bool? light;
  final bool? blueLight;
  final bool? redLight;

  CabinControlsResponse({
    this.temperature,
    this.oxygen,
    this.humidity,
    this.co2,
    this.nebulizer,
    this.sterilize,
    this.fanMode,
    this.airMode,
    this.newFan,
    this.openOxygen,
    this.checkLight,
    this.light,
    this.blueLight,
    this.redLight,
  });

  factory CabinControlsResponse.fromJson(Map<String, dynamic> json) {
    return CabinControlsResponse(
      temperature: (json['temperature'] as num?)?.toDouble(),
      oxygen: (json['oxygen'] as num?)?.toDouble(),
      humidity: (json['humidity'] as num?)?.toDouble(),
      co2: (json['co2'] as num?)?.toDouble(),
      nebulizer: json['nebulizer'] as int?,
      sterilize: json['sterilize'] as int?,
      fanMode: json['fanMode'] as String?,
      airMode: json['airMode'] as String?,
      newFan: json['newFan'] as bool?,
      openOxygen: json['openOxygen'] as bool?,
      checkLight: json['checkLight'] as bool?,
      light: json['light'] as bool?,
      blueLight: json['blueLight'] as bool?,
      redLight: json['redLight'] as bool?,
    );
  }

  CabinControlsResponse copyWith({
    double? temperature,
    double? oxygen,
    double? humidity,
    double? co2,
    int? nebulizer,
    int? sterilize,
    String? fanMode,
    String? airMode,
    bool? newFan,
    bool? openOxygen,
    bool? checkLight,
    bool? light,
    bool? blueLight,
    bool? redLight,
  }) {
    return CabinControlsResponse(
      temperature: temperature ?? this.temperature,
      oxygen: oxygen ?? this.oxygen,
      humidity: humidity ?? this.humidity,
      co2: co2 ?? this.co2,
      nebulizer: nebulizer ?? this.nebulizer,
      sterilize: sterilize ?? this.sterilize,
      fanMode: fanMode ?? this.fanMode,
      airMode: airMode ?? this.airMode,
      newFan: newFan ?? this.newFan,
      openOxygen: openOxygen ?? this.openOxygen,
      checkLight: checkLight ?? this.checkLight,
      light: light ?? this.light,
      blueLight: blueLight ?? this.blueLight,
      redLight: redLight ?? this.redLight,
    );
  }
}
