import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
  UseGuards,
  Request,
  Patch,
} from '@nestjs/common';
// import { AuthGuard } from 'src/auth/auth.guard';

import { ApiBearerAuth, ApiTags, ApiOperation } from '@nestjs/swagger';
import * as dto from './dto/index';
import { AdminService } from './admin.service';
import { Commission } from './dto/admin';
import { DeactivateChefDto } from './dto/deactivate_chef.dto';
import { AuthGuard } from '../auth/auth.guard';
// import { RolesGuard } from 'src/auth/roles.guard';

@ApiTags('Admin')
@Controller('admin')
export class AdminController {
  constructor(private readonly AdminService: AdminService) {}

  @Post('login')
  async login(@Body() dto: dto.adminLogin) {
    try {
      let data = await this.AdminService.login(dto);
      let response = {
        success: true,
        message:
          "Welcome back! You've successfully logged into your account. Feel free to explore and enjoy our services",
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @Get('profile')
  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  async admin_profile(@Request() req: any) {
    try {
      let data = await this.AdminService.admin_profile(req);
      return data;
    } catch (err) {
      throw err;
    }
  }

  @Put('profile')
  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  async edit_admin_profile(@Body() dto: dto.editProfile, @Request() req: any) {
    try {
      let data = await this.AdminService.edit_profile(dto, req);
      let response = {
        message: 'Logged in',
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  @Put('password')
  async admin_change_password(
    @Body() dto: dto.adminChangePass,
    @Request() req: any
  ) {
    try {
      let data = await this.AdminService.changePassword(dto, req);
      let response = {
        message:
          'Your password has been changed successfully. You can now log in with your new password.',
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }
}
