/**
 * Ledger Image Controller
 */
import { Controller, Get, Put, Delete, Param, Body, UseGuards } from '@nestjs/common';
import { LedgerImageService } from './ledger-image.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('ledger-image')
@UseGuards(JwtAuthGuard)
export class LedgerImageController {
  constructor(private ledgerImageService: LedgerImageService) {}

  @Get(':actNo/image')
  async getImage(@Param('actNo') actNo: string) {
    const img = await this.ledgerImageService.findByActNo(actNo);
    return img ?? { img: null, note: null };
  }

  @Put(':actNo/image')
  upsertImage(
    @Param('actNo') actNo: string,
    @Body() body: { img?: string; note?: string },
  ) {
    return this.ledgerImageService.upsert(actNo, body.img ?? null, body.note);
  }

  @Delete(':actNo/image')
  deleteImage(@Param('actNo') actNo: string) {
    return this.ledgerImageService.delete(actNo);
  }
}
