import { Body, Controller, Delete, Get, Param, Patch, Post, Query, Request } from '@nestjs/common';
import { SharesService, CreateShareDto, UpdateShareDto, TransferShareDto } from './shares.service';

@Controller('shares')
export class SharesController {
  constructor(private svc: SharesService) {}

  @Get()
  findAll(@Query('q') q?: string, @Query('shareType') shareType?: string, @Query('status') status?: string,
    @Query('memberId') memberId?: string, @Query('page') page?: string, @Query('limit') limit?: string) {
    return this.svc.findAll({ q, shareType, status, memberId, page: Number(page ?? 1), limit: Number(limit ?? 20) });
  }

  @Get('summary')
  getSummary(@Query('memberId') memberId?: string) {
    return this.svc.getSummary(memberId);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.svc.findOne(id);
  }

  @Post()
  create(@Body() dto: CreateShareDto) {
    return this.svc.create(dto);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() dto: UpdateShareDto) {
    return this.svc.update(id, dto);
  }

  @Post(':id/transfer')
  transfer(@Param('id') id: string, @Body() dto: TransferShareDto) {
    return this.svc.transfer(id, dto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.svc.remove(id);
  }
}
