import {
  Controller,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Get,
  Query,
} from '@nestjs/common';
import { TokenData } from 'src/common/decorator/token-data.decorator';
import { TokenDataEntity } from 'src/common/entities/token-data.entity';
import { EvaluationIndicatorDto } from '../dto/evaluation-indicator.dto';
import { StudentEvaluationDto } from '../dto/student-evaluation.dto';
import { EvaluationIndicatorService } from '../service/evaluation-indicator.service';

@Controller('evaluation/indicator')
export class EvaluationIndicatorController {
  constructor(
    private readonly evaluationIndicatorService: EvaluationIndicatorService,
  ) {}

  @Post()
  create(
    @Body() data: EvaluationIndicatorDto,
    @TokenData() token: TokenDataEntity,
  ) {
    data.updater = data.creator = token.userId;
    return this.evaluationIndicatorService.create(data);
  }

  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() updateEvaluationDto: EvaluationIndicatorDto,
  ) {
    return this.evaluationIndicatorService.update(+id, updateEvaluationDto);
  }

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

  @Get('findAllStudentEvaluation')
  findAllStudentEvaluation(@Query('orgId') orgId: string) {
    return this.evaluationIndicatorService.findAllStudentEvaluation(+orgId);
  }

  @Post('createStudentEvaluationScore')
  createStudentEvaluationScore(
    @Body() studentEvaluationDto: StudentEvaluationDto,
    @TokenData() token: TokenDataEntity,
  ) {
    studentEvaluationDto.updater = studentEvaluationDto.creator = token.userId;
    return this.evaluationIndicatorService.createStudentEvaluationScore(
      studentEvaluationDto,
    );
  }

  @Patch('updateStudentEvaluationScore/:id')
  updateStudentEvaluationScore(
    @Param('id') id: string,
    @Body() studentEvaluationDto: StudentEvaluationDto,
    @TokenData() token: TokenDataEntity,
  ) {
    studentEvaluationDto.updater = token.userId;
    return this.evaluationIndicatorService.updateStudentEvaluationScore(
      +id,
      studentEvaluationDto,
    );
  }
}
