package dev.banking.model;

/**
 * Represents a transfer operation between two accounts.
 */
public final class TransferTransaction
        extends Transaction {

    private final int sourceAccountId;
    private final int targetAccountId;

    public TransferTransaction(
            int sourceAccountId,
            int targetAccountId,
            int amount
    ) {
        super(amount);

        if (sourceAccountId < 0) {
            throw new IllegalArgumentException(
                    "Invalid source account id."
            );
        }

        if (targetAccountId < 0) {
            throw new IllegalArgumentException(
                    "Invalid target account id."
            );
        }

        if (sourceAccountId == targetAccountId) {
            throw new IllegalArgumentException(
                    "Source and target accounts must be different."
            );
        }

        this.sourceAccountId = sourceAccountId;
        this.targetAccountId = targetAccountId;
    }

    public int getSourceAccountId() {
        return sourceAccountId;
    }

    public int getTargetAccountId() {
        return targetAccountId;
    }

    @Override
    public String toString() {
        return "TransferTransaction{" +
                "sourceAccountId=" + sourceAccountId +
                ", targetAccountId=" + targetAccountId +
                ", amount=" + getAmount() +
                '}';
    }
}