import { Body, Controller, Post } from '@nestjs/common';
import { AuthAdminService } from './authAdminservice';
import { CreateAdminDto } from 'src/admin/dto/create-admin.dto';
import { LoginAdminDto } from 'src/auth/admin/dto/login-admin.dto';
import { ApiBody, ApiCreatedResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { AdminSigninResDto } from './dto/admin-signin-res.dto';

@Controller()
@ApiTags('Create admin account and sign in as admin')
export class AuthAdminController {
  constructor(private readonly authAdminService: AuthAdminService) {}

  @ApiBody({ type: CreateAdminDto })
  @ApiCreatedResponse({
    content: {
      'application/json': {
        example: {
          token: 'token',
        },
      },
    },
  })
  @Post('admin/signup')
  async signUp(@Body() createAdminDto: CreateAdminDto) {
    console.log(createAdminDto);
    try {
      const accessToken = await this.authAdminService.signUp(createAdminDto);
      return { token: accessToken };
    } catch (e) {
      return e;
    }
  }
  @ApiBody({ type: LoginAdminDto })
  @ApiCreatedResponse({
    type: AdminSigninResDto,
  })
  @ApiUnauthorizedResponse()
  @Post('admin/signin')
  async signIn(@Body() loginAdminDto: LoginAdminDto) {
    try {
      const adminSigninResDto = await this.authAdminService.signIn(loginAdminDto);
      return adminSigninResDto;
    } catch (e) {
      throw e;
    }
  }
}
