import { FastifyRequest, FastifyReply } from 'fastify';
import { DummyGradesService } from '../../services/DummyGradesService';
import {
    DummyGradeResponse,
    DummyGradeCreateBody,
    DummyGradeUpdateParams,
    DummyGradeDeleteParams
} from '../../types/DummyGradeTypes';

export class DummyGradesController {
    private dummyGradesService: DummyGradesService;

    constructor(dummyGradesService: DummyGradesService) {
        this.dummyGradesService = dummyGradesService;
    }

    async getAllDummyGrades(req: FastifyRequest, reply: FastifyReply): Promise<void> {
        try {
            const response = await this.dummyGradesService.getAllDummyGrades();
            reply.send(response);
        } catch (error) {
            const errorMessage = error instanceof Error ? error.message : 'Internal Server Error';
            reply.status(500).send({ message: errorMessage });
        }
    }

    async addDummyGrade(req: FastifyRequest<{ Body: DummyGradeCreateBody }>, reply: FastifyReply): Promise<void> {
        try {
            const { body } = req;
            const response = await this.dummyGradesService.addDummyGrade(body);
            reply.send(response);
        } catch (error) {
            const errorMessage = error instanceof Error ? error.message : 'Internal Server Error';
            reply.status(500).send({ message: errorMessage });
        }
    }

    async updateDummyGrade(req: FastifyRequest<{ Body: DummyGradeUpdateParams }>, reply: FastifyReply): Promise<void> {
        try {
            const { body } = req;
            const response = await this.dummyGradesService.updateDummyGrade(body);
            reply.send(response);
        } catch (error) {
            const errorMessage = error instanceof Error ? error.message : 'Internal Server Error';
            reply.status(500).send({ message: errorMessage });
        }
    }

    async deleteDummyGrade(req: FastifyRequest<{ Body: DummyGradeDeleteParams }>, reply: FastifyReply): Promise<void> {
        try {
            await this.dummyGradesService.deleteDummyGrade(req.body);
            reply.send({ success: true, message: 'Dummy grade deleted successfully' });
        } catch (error) {
            const errorMessage = error instanceof Error ? error.message : 'Internal Server Error';
            reply.status(500).send({ message: errorMessage });
        }
    }
} 