import {
  Controller,
  Get,
  Post,
  Put,
  Body,
  Param,
  Query,
  UseGuards,
  Request,
} from '@nestjs/common';
import { ParentService } from './parent.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';

@Controller('parent')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('parent')
export class ParentController {
  constructor(private readonly parentService: ParentService) {}

  // ==================== 孩子信息 ====================

  @Get('children')
  getChildren(@Request() req: any) {
    return this.parentService.getChildren(req.user.userId, req.user.tenantId);
  }

  @Get('children/:id')
  getChildProfile(@Request() req: any, @Param('id') id: string) {
    return this.parentService.getChildProfile(req.user.userId, +id, req.user.tenantId);
  }

  // ==================== 阅读记录 ====================

  @Get('children/:id/lessons')
  getChildLessons(@Request() req: any, @Param('id') id: string, @Query() query: any) {
    return this.parentService.getChildLessons(req.user.userId, +id, req.user.tenantId, query);
  }

  // ==================== 任务 ====================

  @Get('children/:id/tasks')
  getChildTasks(@Request() req: any, @Param('id') id: string, @Query() query: any) {
    return this.parentService.getChildTasks(req.user.userId, +id, req.user.tenantId, query);
  }

  @Put('children/:studentId/tasks/:taskId/feedback')
  submitTaskFeedback(
    @Request() req: any,
    @Param('studentId') studentId: string,
    @Param('taskId') taskId: string,
    @Body() body: { feedback: string },
  ) {
    return this.parentService.submitTaskFeedback(
      req.user.userId,
      +studentId,
      +taskId,
      req.user.tenantId,
      body.feedback,
    );
  }

  // ==================== 成长档案 ====================

  @Get('children/:id/growth-records')
  getChildGrowthRecords(@Request() req: any, @Param('id') id: string, @Query() query: any) {
    return this.parentService.getChildGrowthRecords(req.user.userId, +id, req.user.tenantId, query);
  }
}
