import UserMiddleware from "../Middleware/UserAuthorization";
import OnCallDutyPolicyService from "../Services/OnCallDutyPolicyService";
import Response from "../Utils/Response";
import BaseAPI from "./BaseAPI";
import CommonAPI from "./CommonAPI";
import BadDataException from "../../Types/Exception/BadDataException";
import OnCallDutyPolicy from "../../Models/DatabaseModels/OnCallDutyPolicy";
import OnCallDutyPolicyEscalationRuleUser from "../../Models/DatabaseModels/OnCallDutyPolicyEscalationRuleUser";
import OnCallDutyPolicyEscalationRuleTeam from "../../Models/DatabaseModels/OnCallDutyPolicyEscalationRuleTeam";
import OnCallDutyPolicyEscalationRuleSchedule from "../../Models/DatabaseModels/OnCallDutyPolicyEscalationRuleSchedule";
import BaseModel from "../../Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel";
export default class OnCallDutyPolicyAPI extends BaseAPI {
    constructor() {
        var _a;
        super(OnCallDutyPolicy, OnCallDutyPolicyService);
        // CNAME verification api. THis API will be used from the dashboard to validate the CNAME MANUALLY.
        this.router.get(`${(_a = new this.entityType().getCrudApiPath()) === null || _a === void 0 ? void 0 : _a.toString()}/current-on-duty-escalation-policies`, UserMiddleware.getUserMiddleware, async (req, res, next) => {
            try {
                const databaseProps = await CommonAPI.getDatabaseCommonInteractionProps(req);
                const projectId = databaseProps.tenantId;
                const userId = databaseProps.userId;
                if (!projectId) {
                    return Response.sendErrorResponse(req, res, new BadDataException("Invalid projectId."));
                }
                if (!userId) {
                    return Response.sendErrorResponse(req, res, new BadDataException("Invalid userId."));
                }
                const result = await this.service.getOnCallPoliciesWhereUserIsOnCallDuty({
                    projectId: projectId,
                    userId: userId,
                });
                return Response.sendJsonObjectResponse(req, res, {
                    escalationRulesByUser: BaseModel.toJSONArray(result.escalationRulesByUser, OnCallDutyPolicyEscalationRuleUser),
                    escalationRulesByTeam: BaseModel.toJSONArray(result.escalationRulesByTeam, OnCallDutyPolicyEscalationRuleTeam),
                    escalationRulesBySchedule: BaseModel.toJSONArray(result.escalationRulesBySchedule, OnCallDutyPolicyEscalationRuleSchedule),
                });
            }
            catch (e) {
                next(e);
            }
        });
    }
}
//# sourceMappingURL=OnCallDutyPolicyAPI.js.map