import { Token } from '../../../domain/entities/token';
import { NotFoundError } from '../../../domain/errors/not-found-error';
import { ITokenRepository } from '../../../domain/repositories/token-repository';

export interface UpdateTokenMinimumSwapValueInput {
  readonly tokenId: string;
  readonly minimumSwapValue: number | null;
}

export class UpdateTokenMinimumSwapValueUseCase {
  constructor(private readonly tokenRepository: ITokenRepository) {}

  async execute(input: UpdateTokenMinimumSwapValueInput): Promise<Token> {
    const token = await this.tokenRepository.findById(input.tokenId);
    if (!token) {
      throw new NotFoundError('Token', input.tokenId);
    }

    const updated = new Token(
      token.id,
      token.isNative,
      token.address,
      token.networkId,
      token.thumbnail,
      token.name,
      token.symbol,
      token.decimals,
      token.code,
      token.info,
      token.isActive,
      input.minimumSwapValue,
      token.mcap,
      token.createdAt,
      new Date(),
    );

    return this.tokenRepository.update(updated);
  }
}
