import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import '../../../data/models/license/license_dto.dart';
import '../../repositories/license_repository.dart';
import '../../../core/errors/failures.dart';
import '../base_usecase.dart';

/// 라이선스 상세 조회 UseCase
@injectable
class GetLicenseDetailUseCase implements UseCase<LicenseDto, int> {
  final LicenseRepository repository;

  GetLicenseDetailUseCase(this.repository);

  @override
  Future<Either<Failure, LicenseDto>> call(int id) async {
    try {
      final result = await repository.getLicenseById(id);
      return result.map((license) => LicenseDto(
        id: license.id ?? 0,
        licenseKey: license.licenseKey,
        productName: license.productName,
        vendor: license.vendor,
        licenseType: license.licenseType,
        userCount: license.userCount,
        purchaseDate: license.purchaseDate,
        expiryDate: license.expiryDate,
        purchasePrice: license.purchasePrice,
        companyId: license.companyId,
        branchId: license.branchId,
        assignedUserId: license.assignedUserId,
        remark: license.remark,
        isActive: license.isActive ?? true,
        createdAt: license.createdAt ?? DateTime.now(),
        updatedAt: license.updatedAt ?? DateTime.now(),
        companyName: license.companyName,
        branchName: license.branchName,
        assignedUserName: license.assignedUserName,
      ));
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }
}