import { Controller, Get, Query } from '@nestjs/common'
import { PaymentService } from '@/services/payment.service'

@Controller('payments')
export class PaymentController {
	constructor(
		private readonly paymentService: PaymentService,
	) {}

	@Get('add-payment-link')
	async addPaymentLink(@Query() query: { invoiceId: string }) {
        const { invoiceId } = query
		try {
			const paymentLink = await this.paymentService.addPaymentLink(invoiceId)
			return paymentLink?.url
		} catch (error) {
			throw new Error(`Failed to add payment link to invoice ${invoiceId}: ${error.message}`)
		}
	}
}
