import { Controller, Get, Post, Put, Body, UseGuards, Request } from '@nestjs/common';
import { AdminService } from './admin.service';
import { CombinedAuthGuard } from '../auth/combined-auth.guard';
import { RolesGuard } from '../auth/roles.guard';
import { Roles } from '../auth/roles.decorator';
import { UserRole } from '../user/user-role.enum';

@Controller('v1/admin')
@UseGuards(CombinedAuthGuard, RolesGuard)
@Roles(UserRole.TENANT_ADMIN, UserRole.SUPER_ADMIN)
export class AdminController {
    constructor(private readonly adminService: AdminService) { }

    @Get('users')
    async getUsers(@Request() req: any) {
        return this.adminService.getTenantUsers(req.user.tenantId);
    }

    @Get('settings')
    async getSettings(@Request() req: any) {
        return this.adminService.getTenantSettings(req.user.tenantId);
    }

    @Put('settings')
    async updateSettings(@Request() req: any, @Body() body: any) {
        return this.adminService.updateTenantSettings(req.user.tenantId, body);
    }

    @Get('pending-shares')
    async getPendingShares(@Request() req: any) {
        return this.adminService.getPendingShares(req.user.tenantId);
    }
}
