import 'package:dartz/dartz.dart';
import '../../../services/company_service.dart';
import '../../../core/errors/failures.dart';
import '../base_usecase.dart';

/// 회사 상태 토글 파라미터
class ToggleCompanyStatusParams {
  final int id;
  final bool isActive;

  const ToggleCompanyStatusParams({
    required this.id,
    required this.isActive,
  });
}

/// 회사 활성화/비활성화 UseCase
class ToggleCompanyStatusUseCase extends UseCase<void, ToggleCompanyStatusParams> {
  final CompanyService _companyService;

  ToggleCompanyStatusUseCase(this._companyService);

  @override
  Future<Either<Failure, void>> call(ToggleCompanyStatusParams params) async {
    try {
      await _companyService.updateCompanyStatus(params.id, params.isActive);
      return const Right(null);
    } on ServerFailure catch (e) {
      if (e.message.contains('equipment')) {
        return Left(ValidationFailure(
          message: '활성 장비가 있는 회사는 비활성화할 수 없습니다.',
          code: 'HAS_ACTIVE_EQUIPMENT',
        ));
      }
      return Left(ServerFailure(
        message: e.message,
      ));
    } catch (e) {
      return Left(ServerFailure(
        message: '회사 상태 변경 중 오류가 발생했습니다.',
      ));
    }
  }
}