import { Body, Controller, Get, Patch, Post, Query, UseGuards } from '@nestjs/common';
import { SubscriptionsService } from './subscriptions.service';
import { ApiBearerAuth, ApiBody, ApiQuery, ApiTags } from '@nestjs/swagger';
import { RolesGuard } from 'src/guards/roles.guard';
import { Roles } from 'src/common/decorators/roles.decorator';
import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
import { USER_ROLE } from '../users/users.constant';
import { ResponseMessage } from 'src/common/decorators/response_message.decorator';
import { CurrentUser } from 'src/common/decorators/user.decorator';
import { IFullUser } from '../users/users.interface';
import { ChangeModelDto, ChangePlanDto, UpdateFeatureSettingsDto } from './subscriptions.validation';

@ApiTags("Subscriptions")
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('subscriptions')
export class SubscriptionsController {

	constructor(private readonly subscriptionsService: SubscriptionsService) { }

	// @Get()
	// @UseGuards(RolesGuard)
	// @Roles(USER_ROLE.user)
	// @ResponseMessage("Subscriptions fetched successfully")
	// async getAllSubscriptions() {
	//     return await this.subscriptionsService.getAllSubscriptions();
	// }

	@Get('my-subscription')
	@ResponseMessage("Subscription fetched successfully")
	async getMySubscription(
		@CurrentUser() user: IFullUser
	) {
		return await this.subscriptionsService.getMySubscription(user);
	}


	// @Post('change-plan')
	// @ResponseMessage("Plan changed successfully")
	// @ApiBody({ type: ChangePlanDto })
	// async changePlan(
	// 	@CurrentUser() user: IFullUser,
	// 	@Body() { plan }: ChangePlanDto
	// ) {
	// 	return await this.subscriptionsService.changeSubscriptionPlan(user, plan)
	// }


	@Patch('update-model')
	@ResponseMessage("Model updated successfully")
	@ApiBody({ type: ChangeModelDto })
	async changeSubscription(
		@CurrentUser() user: IFullUser,
		@Body() body: ChangeModelDto
	) {
		return await this.subscriptionsService.updateAiModel(body, user);
	}


	@Patch('toggle-image-enhancer')
	@ResponseMessage("Prompt Enhancer toggled successfully")
	async togglePromptEnhancer(
		@CurrentUser() user: IFullUser
	) {
		return await this.subscriptionsService.togglePromptEnhancer(user);
	}



	@Patch('update-feature-settings')
	@ResponseMessage("Feature settings updated successfully")
	@ApiBody({ type: UpdateFeatureSettingsDto })
	async updateFeatureSettings(
		@CurrentUser() user: IFullUser,
		@Body() body: UpdateFeatureSettingsDto
	) {
		return await this.subscriptionsService.updateFeatureSettings(user, body);
	}
}
