"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AttendanceController = void 0;
const common_1 = require("@nestjs/common");
const attendance_service_1 = require("./attendance.service");
const jwt_auth_guard_1 = require("../common/guards/jwt-auth.guard");
const roles_guard_1 = require("../common/guards/roles.guard");
const roles_decorator_1 = require("../common/decorators/roles.decorator");
const role_enum_1 = require("../common/roles/role.enum");
const mark_attendance_dto_1 = require("./dto/mark-attendance.dto");
const current_user_decorator_1 = require("../common/decorators/current-user.decorator");
const student_month_dto_1 = require("./dto/student-month.dto");
const bulk_mark_dto_1 = require("./dto/bulk-mark.dto");
const report_dto_1 = require("./dto/report.dto");
let AttendanceController = class AttendanceController {
    svc;
    constructor(svc) {
        this.svc = svc;
    }
    async bulkMark(teacherId, userRole, body, ayId) {
        return this.svc.bulkMarkAttendance(body, teacherId, ayId, userRole);
    }
    async mark(teacherId, userRole, dto, ayId) {
        return this.svc.markAttendance(dto, teacherId, ayId, userRole);
    }
    async summary(query, ayId) {
        const filter = { ...query, academicYearId: query.academicYearId ?? ayId };
        if (String(query.summary) === 'true')
            return this.svc.getAdminSummary(filter);
        return this.svc.getAttendance(filter);
    }
    async report(query, ayId) {
        const { period, ...filter } = query;
        const filterWithAy = { ...filter, academicYearId: query.academicYearId ?? ayId };
        return this.svc.getReport(filterWithAy, period);
    }
    async teacherHistory(teacherId) {
        return this.svc.getTeacherHistory(teacherId);
    }
    async sectionDay(sectionId, date, ayId) {
        return this.svc.getSectionDay(sectionId, date, ayId);
    }
    async myAttendance(studentId, from, to, ayId) {
        return this.svc.getStudentRange(studentId, { from, to }, ayId);
    }
    async myMonth(studentId, q, ayId) {
        const month = q?.month || new Date().toISOString().slice(0, 7);
        const academicYearId = q.academicYearId ?? ayId;
        return this.svc.getStudentMonth(studentId, month, academicYearId);
    }
    async studentMonth(studentId, q, ayId) {
        const month = q?.month || new Date().toISOString().slice(0, 7);
        const academicYearId = q.academicYearId ?? ayId;
        return this.svc.getStudentMonth(studentId, month, academicYearId);
    }
    getAttendanceStats(ayId) {
        return this.svc.getDailySummary(ayId);
    }
};
exports.AttendanceController = AttendanceController;
__decorate([
    (0, common_1.Post)('bulk'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.ADMIN, role_enum_1.Role.TEACHER),
    __param(0, (0, current_user_decorator_1.CurrentUser)('id')),
    __param(1, (0, current_user_decorator_1.CurrentUser)('role')),
    __param(2, (0, common_1.Body)()),
    __param(3, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, bulk_mark_dto_1.BulkMarkDto, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "bulkMark", null);
__decorate([
    (0, common_1.Post)('mark'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.ADMIN, role_enum_1.Role.TEACHER),
    __param(0, (0, current_user_decorator_1.CurrentUser)('id')),
    __param(1, (0, current_user_decorator_1.CurrentUser)('role')),
    __param(2, (0, common_1.Body)()),
    __param(3, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, mark_attendance_dto_1.MarkAttendanceDto, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "mark", null);
__decorate([
    (0, common_1.Get)(),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.ADMIN),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "summary", null);
__decorate([
    (0, common_1.Get)('report'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.ADMIN),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_dto_1.ReportDto, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "report", null);
__decorate([
    (0, common_1.Get)('history'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.TEACHER),
    __param(0, (0, current_user_decorator_1.CurrentUser)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "teacherHistory", null);
__decorate([
    (0, common_1.Get)('section-day'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.ADMIN, role_enum_1.Role.TEACHER),
    __param(0, (0, common_1.Query)('sectionId')),
    __param(1, (0, common_1.Query)('date')),
    __param(2, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "sectionDay", null);
__decorate([
    (0, common_1.Get)('me'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.STUDENT),
    __param(0, (0, current_user_decorator_1.CurrentUser)('id')),
    __param(1, (0, common_1.Query)('from')),
    __param(2, (0, common_1.Query)('to')),
    __param(3, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, String, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "myAttendance", null);
__decorate([
    (0, common_1.Get)('me/month'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.STUDENT),
    __param(0, (0, current_user_decorator_1.CurrentUser)('id')),
    __param(1, (0, common_1.Query)()),
    __param(2, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, student_month_dto_1.StudentMonthQueryDto, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "myMonth", null);
__decorate([
    (0, common_1.Get)('student/:studentId'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.ADMIN, role_enum_1.Role.TEACHER),
    __param(0, (0, common_1.Param)('studentId')),
    __param(1, (0, common_1.Query)()),
    __param(2, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, student_month_dto_1.StudentMonthQueryDto, String]),
    __metadata("design:returntype", Promise)
], AttendanceController.prototype, "studentMonth", null);
__decorate([
    (0, common_1.Get)('summary'),
    (0, roles_decorator_1.Roles)(role_enum_1.Role.ADMIN),
    __param(0, (0, common_1.Headers)('x-academic-year-id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", void 0)
], AttendanceController.prototype, "getAttendanceStats", null);
exports.AttendanceController = AttendanceController = __decorate([
    (0, common_1.Controller)('attendance'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard),
    __metadata("design:paramtypes", [attendance_service_1.AttendanceService])
], AttendanceController);
//# sourceMappingURL=attendance.controller.js.map