import { AuthMethod, MultiTenancyInterceptor, UseAuth } from '@backend/auth'
import { Body, Controller, Get, Patch, Post, UseInterceptors } from '@nestjs/common'
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'
import { BillingService } from '../services'
import { BillingProfileResponse, CreateBillingProfileRequest, CreateBillingProfileResponse } from '../types'

@UseAuth(AuthMethod.JWT)
@UseInterceptors(MultiTenancyInterceptor)
@Controller('billing')
@ApiTags('default')
export class BillingController {
	constructor(private readonly _billingService: BillingService) {}

	@Get('profile')
	@ApiOperation({ summary: 'Get the billing profile for the current tenant' })
	@ApiResponse({
		status: 200,
		description: 'The billing profile for the current tenant',
		type: BillingProfileResponse,
	})
	async findBillingProfile(): Promise<BillingProfileResponse> {
		return this._billingService.findBillingProfile()
	}

	@Post('profile')
	@ApiOperation({ summary: 'Create a billing profile for the current tenant' })
	@ApiResponse({
		status: 200,
		description: 'The billing profile for the current tenant',
		type: CreateBillingProfileResponse,
	})
	async createBillingProfile(@Body() request: CreateBillingProfileRequest): Promise<CreateBillingProfileResponse> {
		return this._billingService.createBillingProfile(request)
	}

	@Patch('profile/onboarding')
	@ApiOperation({ summary: 'Get the onboarding URL for the current tenant' })
	@ApiResponse({
		status: 200,
		description: 'The onboarding URL for the current tenant',
		type: CreateBillingProfileResponse,
	})
	async getOnBoardingUrl(@Body() request: CreateBillingProfileRequest): Promise<CreateBillingProfileResponse> {
		return this._billingService.getOnBoardingUrl(request)
	}
}
