import { NotFoundError } from '../../../domain/errors/not-found-error';
import { IAddressRepository } from '../../../domain/repositories/address-repository';

export interface AddressRecord {
  readonly id: string;
  readonly address: string;
  readonly type: string;
  readonly walletId: string;
}

export class GetAddressByAddressUseCase {
  constructor(private readonly addressRepository: IAddressRepository) {}

  async execute(address: string): Promise<AddressRecord> {
    const record = await this.addressRepository.findByAddress(address);
    if (!record) {
      throw new NotFoundError('Address', address);
    }

    return {
      id: record.id,
      address: record.address,
      type: record.type,
      walletId: record.walletId,
    };
  }
}
