package org.initialde.yakasave.Domain.Entities;

import lombok.Getter;
import org.initialde.yakasave.Domain.Enums.TypeSavingsFund;
import org.initialde.yakasave.Domain.ValueObject.Amount;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;

@Getter
public class SavingsFundBuilder {
    private UUID id = UUID.randomUUID();
    private String reference;
    private String goalTitle;
    private String goalDescription;
    private Amount goalAmount;
    private boolean isActive = true;
    private User owner;
    private TypeSavingsFund type;
    private Amount balance = Amount.ZERO;
    private LocalDate launchDate = LocalDate.now();
    private LocalDate deadline;
    private boolean needsApproval = false;
    private int maxAllowedMembers;
    private Collection<WithdrawalApproval> receiptApprovals = new ArrayList<>();
    private Collection<User> contributors = new ArrayList<>();
    private Collection<Contribution> contributions = new ArrayList<>();

    public SavingsFundBuilder id(UUID id) {
        this.id = id;
        return this;
    }

    public SavingsFundBuilder reference(String reference) {
        this.reference = reference;
        return this;
    }

    public SavingsFundBuilder goalTitle(String goalTitle) {
        this.goalTitle = goalTitle;
        return this;
    }

    public SavingsFundBuilder type(TypeSavingsFund type) {
        this.type = type;
        return this;
    }

    public SavingsFundBuilder goalDescription(String goalDescription) {
        this.goalDescription = goalDescription;
        return this;
    }

    public SavingsFundBuilder owner(User owner) {
        this.owner = owner;
        return this;
    }

    public SavingsFundBuilder contributors(Collection<User> contributors) {
        this.contributors = new ArrayList<>(contributors);
        return this;
    }

    public SavingsFundBuilder receiptApprovals(Collection<WithdrawalApproval> approvals) {
        this.receiptApprovals = new ArrayList<>(approvals);
        return this;
    }

    public SavingsFundBuilder contributions(Collection<Contribution> contributions) {
        this.contributions = new ArrayList<>(contributions);
        return this;
    }

    public SavingsFundBuilder goalAmount(double goalAmount) {
        return this.goalAmount(Amount.of(goalAmount));
    }

    public SavingsFundBuilder goalAmount(Amount goalAmount) {
        this.goalAmount = goalAmount;
        return this;
    }

    public SavingsFundBuilder isActive(boolean isActive) {
        this.isActive = isActive;
        return this;
    }

    public SavingsFundBuilder balance(Amount balance) {
        this.balance = balance;
        return this;
    }

    public SavingsFundBuilder balance(double balance) {
        return this.balance(Amount.of(balance));
    }

    public SavingsFundBuilder launchDate(LocalDate launchDate) {
        this.launchDate = launchDate;
        return this;
    }

    public SavingsFundBuilder deadline(LocalDate deadline) {
        this.deadline = deadline;
        return this;
    }

    public SavingsFundBuilder needsApproval(boolean hasRequiredApproval) {
        this.needsApproval = hasRequiredApproval;
        return this;
    }

    public SavingsFundBuilder maxAllowedMembers(int maxAllowedMembers) {
        this.maxAllowedMembers = maxAllowedMembers;
        return this;
    }

    public SavingsFund build() {
        return new SavingsFund(this);
    }
}
