import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:smart_hotel_app/views/report/rule/cubit/rule_management_state.dart';

class RuleManagementCubit extends Cubit<RuleManagementState> {
  RuleManagementCubit() : super(const RuleManagementState()) {
    _initData();
  }

  void _initData() {
    final rules = [
      const RuleInfo(
        id: '1',
        name: '退房自动断电',
        description: '酒管系统—酒度状态',
        enabled: true,
        triggerCondition: '酒管系统—酒度状态',
        action: '断电',
        icon: Icons.logout_outlined,
      ),
      const RuleInfo(
        id: '2',
        name: '清洁中请自动开灯',
        description: '服务彩忧消洁中调',
        enabled: true,
        triggerCondition: '服务彩忧消洁中调',
        action: '开灯',
        icon: Icons.cleaning_services_outlined,
      ),
      const RuleInfo(
        id: '3',
        name: '温度过高自动保护',
        description: '温度·80°C—断电+告管',
        enabled: true,
        triggerCondition: '温度·80°C',
        action: '断电+告管',
        icon: Icons.thermostat_outlined,
      ),
      const RuleInfo(
        id: '4',
        name: '深夜低功事休眠',
        description: '23:00-06:00 平&lt;50W',
        enabled: false,
        triggerCondition: '23:00-06:00 平&lt;50W',
        action: '休眠',
        icon: Icons.nightlight_outlined,
      ),
      const RuleInfo(
        id: '5',
        name: '定时全楼巡检提醒',
        description: '国日 09:00/15.00',
        enabled: true,
        triggerCondition: '国日 09:00/15.00',
        action: '提醒',
        icon: Icons.access_time_outlined,
      ),
    ];

    emit(state.copyWith(rules: rules));
  }

  void toggleRule(String id) {
    final updatedRules = state.rules.map((rule) {
      if (rule.id == id) {
        return rule.copyWith(enabled: !rule.enabled);
      }
      return rule;
    }).toList();

    emit(state.copyWith(rules: updatedRules));
  }
}
