import 'package:dartz/dartz.dart';
import '../../repositories/company_repository.dart';
import '../../../core/constants/app_constants.dart';
import '../../../models/company_model.dart';
import '../../../data/models/common/paginated_response.dart';
import '../../../core/errors/failures.dart';
import '../base_usecase.dart';

/// 회사 목록 조회 파라미터
class GetCompaniesParams {
  final int page;
  final int perPage;
  final String? search;
  final bool? isActive;

  const GetCompaniesParams({
    this.page = 1,
    this.perPage = AppConstants.companyPageSize,
    this.search,
    this.isActive,
  });
}

/// 회사 목록 조회 UseCase
class GetCompaniesUseCase extends UseCase<PaginatedResponse<Company>, GetCompaniesParams> {
  final CompanyRepository _companyRepository;

  GetCompaniesUseCase(this._companyRepository);

  @override
  Future<Either<Failure, PaginatedResponse<Company>>> call(GetCompaniesParams params) async {
    try {
      final result = await _companyRepository.getCompanies(
        page: params.page,
        limit: params.perPage,
        search: params.search,
      );
      
      return result;
    } catch (e) {
      return Left(UnknownFailure(
        message: '회사 목록을 불러오는 중 오류가 발생했습니다.',
        originalError: e,
      ));
    }
  }
}