import { Controller, Get, Post, Param, UseGuards, Req } from '@nestjs/common';
import { Request } from 'express';
import { ItemService } from './item.service';
import { AuthGuard } from '../auth/guards/auth.guard';
import { User } from '../user/user.entity';

@Controller('items')
export class ItemController {
  constructor(private readonly itemService: ItemService) {}

  @Get()
  findAll() {
    return this.itemService.findAll();
  }

  @Get('inventory')
  @UseGuards(AuthGuard)
  getInventory(@Req() req: Request & { user: User }) {
    return this.itemService.getInventory(req.user);
  }

  @Post('equip/:charItemId')
  @UseGuards(AuthGuard)
  equip(@Param('charItemId') charItemId: string, @Req() req: Request & { user: User }) {
    return this.itemService.equip(charItemId, req.user);
  }

  @Post('unequip/:slot')
  @UseGuards(AuthGuard)
  unequip(@Param('slot') slot: 'weapon' | 'armor', @Req() req: Request & { user: User }) {
    return this.itemService.unequip(slot, req.user);
  }
}
