import { Controller, Get, Post, Patch, Body, Param, Query, UseGuards } from '@nestjs/common';
import { DisputesService } from './disputes.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';

@Controller('disputes')
@UseGuards(JwtAuthGuard)
export class DisputesController {
    constructor(private readonly disputesService: DisputesService) { }

    @Get()
    async list(
        @Query('page') page = '1',
        @Query('limit') limit = '20',
        @Query('status') status?: string,
    ) {
        return this.disputesService.list({
            page: parseInt(page, 10),
            limit: parseInt(limit, 10),
            status,
        });
    }

    @Get(':id')
    async getById(@Param('id') id: string) {
        return this.disputesService.getById(id);
    }

    @Post()
    async create(@Body() data: {
        orderId: string;
        buyerId: string;
        sellerId: string;
        reason: string;
        description: string;
    }) {
        return this.disputesService.create(data);
    }

    @Patch(':id/resolve')
    async resolve(
        @Param('id') id: string,
        @Body() data: {
            resolution: 'refund_buyer' | 'favor_seller' | 'partial_refund';
            refundAmountCents?: number;
            notes: string;
        },
    ) {
        return this.disputesService.resolve(id, data);
    }
}
