/**
 * Accounting Controller
 *
 * REST endpoints for DoAcount, UnDoAcount
 */
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { AccountingService } from './accounting.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('accounting')
@UseGuards(JwtAuthGuard)
export class AccountingController {
  constructor(private accountingService: AccountingService) {}

  /**
   * POST /api/accounting/do-acount
   * Maps to: DoAcount(N, kind, ref)
   */
  @Post('do-acount')
  async doAcount(@Body() body: { n: number; kind: number; ref: number }) {
    const { n, kind, ref } = body;
    if (n == null || kind == null || ref == null) {
      return { success: false, error: 'n, kind, ref are required' };
    }
    return this.accountingService.doAcount(n, kind, ref);
  }

  /**
   * POST /api/accounting/undo-acount
   * Maps to: UnDoAcount(N, kind, ref)
   */
  @Post('undo-acount')
  async unDoAcount(@Body() body: { n: number; kind: number; ref: number }) {
    const { n, kind, ref } = body;
    if (n == null || kind == null || ref == null) {
      return { success: false, error: 'n, kind, ref are required' };
    }
    return this.accountingService.unDoAcount(n, kind, ref);
  }
}
