// SPDX-License-Identifier: AGPL-3.0-or-later

import type {DonationCurrency} from '@fluxer/schema/src/domains/donation/DonationSchemas';
import type {IDonationService} from './IDonationService';
import type {DonationCheckoutService} from './services/DonationCheckoutService';
import type {DonationMagicLinkService} from './services/DonationMagicLinkService';

export class DonationService implements IDonationService {
	constructor(
		private magicLinkService: DonationMagicLinkService,
		private checkoutService: DonationCheckoutService,
	) {}

	async requestMagicLink(email: string): Promise<void> {
		return this.magicLinkService.sendMagicLink(email);
	}

	async validateMagicLinkToken(token: string): Promise<{
		email: string;
		stripeCustomerId: string | null;
	}> {
		return this.magicLinkService.validateToken(token);
	}

	async createDonationCheckout(params: {
		email: string;
		amountCents: number;
		currency: DonationCurrency;
		interval: 'month' | 'year' | null;
		isBusiness?: boolean;
	}): Promise<string> {
		return this.checkoutService.createCheckout(params);
	}

	async createDonorPortalSession(stripeCustomerId: string): Promise<string> {
		return this.checkoutService.createPortalSession(stripeCustomerId);
	}
}
