import UserMiddleware from "../Middleware/UserAuthorization";
import TeamComplianceService from "../Services/TeamComplianceService";
import Response from "../Utils/Response";
import BaseAPI from "./BaseAPI";
import CommonAPI from "./CommonAPI";
import BadDataException from "../../Types/Exception/BadDataException";
import ObjectID from "../../Types/ObjectID";
import Team from "../../Models/DatabaseModels/Team";
import TeamService from "../Services/TeamService";
export default class TeamComplianceAPI extends BaseAPI {
    constructor() {
        var _a;
        super(Team, TeamService);
        // Get team compliance status
        this.router.get(`${(_a = new this.entityType().getCrudApiPath()) === null || _a === void 0 ? void 0 : _a.toString()}/compliance-status/:teamId`, UserMiddleware.getUserMiddleware, async (req, res, next) => {
            try {
                const databaseProps = await CommonAPI.getDatabaseCommonInteractionProps(req);
                const projectId = databaseProps.tenantId;
                const teamId = new ObjectID(req.params["teamId"]);
                if (!projectId) {
                    return Response.sendErrorResponse(req, res, new BadDataException("Invalid projectId."));
                }
                if (!teamId) {
                    return Response.sendErrorResponse(req, res, new BadDataException("Invalid teamId."));
                }
                const complianceStatus = await TeamComplianceService.getTeamComplianceStatus(teamId, projectId);
                // Convert ObjectIDs to strings for JSON response
                const responseData = {
                    teamId: complianceStatus.teamId.toString(),
                    teamName: complianceStatus.teamName,
                    complianceSettings: complianceStatus.complianceSettings,
                    userComplianceStatuses: complianceStatus.userComplianceStatuses.map((user) => {
                        var _a;
                        return {
                            userId: user.userId.toString(),
                            userName: user.userName,
                            userEmail: user.userEmail,
                            userProfilePictureId: (_a = user.userProfilePictureId) === null || _a === void 0 ? void 0 : _a.toString(),
                            isCompliant: user.isCompliant,
                            nonCompliantRules: user.nonCompliantRules,
                        };
                    }),
                };
                return Response.sendJsonObjectResponse(req, res, responseData);
            }
            catch (e) {
                next(e);
            }
        });
    }
}
//# sourceMappingURL=TeamComplianceAPI.js.map