package org.initialde.yakasave.Api.Responses;

import io.swagger.v3.oas.annotations.media.Schema;
import org.initialde.yakasave.Domain.Entities.SavingsFund;

import java.time.LocalDate;

@Schema(description = "Represents a collective savings fund")
public record RetrievedCollectiveSavingsFund(
        @Schema(description = "Title of the savings goal") String goalTitle,
        @Schema(description = "Target amount to be saved") double goalAmount,
        @Schema(description = "Current saved amount") double currentBalance,
        @Schema(description = "Unique reference for the fund") String reference,
        @Schema(description = "Date when the fund was launched") LocalDate launchDate,
        @Schema(description = "Deadline to reach the savings goal") LocalDate deadline,
        @Schema(description = "Whether approval is required to use the funds") boolean needsApproval,
        @Schema(description = "Maximum number of members allowed in the fund") int maxAllowedMembers
) {
    public static RetrievedCollectiveSavingsFund fromSavingsFunds(SavingsFund savingsFund) {
        return new RetrievedCollectiveSavingsFund(
                savingsFund.getTitle(),
                savingsFund.getGoalAmount().toDouble(),
                savingsFund.getBalance().toDouble(),
                savingsFund.getReference(),
                savingsFund.getLaunchDate(),
                savingsFund.getDeadline(),
                savingsFund.isNeedsApproval(),
                savingsFund.getMaxAllowedMembers()
        );
    }
}
