"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../types");
const openapi_1 = require("../../openapi");
const controller_1 = __importDefault(require("../../routes/controller"));
const error_1 = require("../../error");
const PATH = '/:projectId/features/:featureName/lifecycle';
class FeatureLifecycleController extends controller_1.default {
    constructor(config, { featureLifecycleService, openApiService, }) {
        super(config);
        this.featureLifecycleService = featureLifecycleService;
        this.openApiService = openApiService;
        this.flagResolver = config.flagResolver;
        this.route({
            method: 'get',
            path: PATH,
            handler: this.getFeatureLifecycle,
            permission: types_1.NONE,
            middleware: [
                openApiService.validPath({
                    tags: ['Unstable'],
                    summary: 'Get feature lifecycle',
                    description: 'Information about the lifecycle stages of the feature.',
                    operationId: 'getFeatureLifecycle',
                    responses: {
                        200: (0, openapi_1.createResponseSchema)('featureLifecycleSchema'),
                        ...(0, openapi_1.getStandardResponses)(401, 403, 404),
                    },
                }),
            ],
        });
        this.route({
            method: 'post',
            path: `${PATH}/complete`,
            handler: this.complete,
            permission: types_1.UPDATE_FEATURE,
            acceptAnyContentType: true,
            middleware: [
                openApiService.validPath({
                    tags: ['Unstable'],
                    summary: 'Set feature completed',
                    description: 'This will set the feature as completed.',
                    operationId: 'complete',
                    responses: {
                        200: openapi_1.emptyResponse,
                        ...(0, openapi_1.getStandardResponses)(401, 403, 404),
                    },
                }),
            ],
        });
        this.route({
            method: 'post',
            path: `${PATH}/uncomplete`,
            handler: this.uncomplete,
            permission: types_1.UPDATE_FEATURE,
            acceptAnyContentType: true,
            middleware: [
                openApiService.validPath({
                    tags: ['Unstable'],
                    summary: 'Set feature uncompleted',
                    description: 'This will set the feature as uncompleted.',
                    operationId: 'uncomplete',
                    responses: {
                        200: openapi_1.emptyResponse,
                        ...(0, openapi_1.getStandardResponses)(401, 403, 404),
                    },
                }),
            ],
        });
    }
    async getFeatureLifecycle(req, res) {
        if (!this.flagResolver.isEnabled('featureLifecycle')) {
            throw new error_1.NotFoundError('Feature lifecycle is disabled.');
        }
        const { featureName } = req.params;
        const result = await this.featureLifecycleService.getFeatureLifecycle(featureName);
        this.openApiService.respondWithValidation(200, res, openapi_1.featureLifecycleSchema.$id, (0, types_1.serializeDates)(result));
    }
    async complete(req, res) {
        if (!this.flagResolver.isEnabled('featureLifecycle')) {
            throw new error_1.NotFoundError('Feature lifecycle is disabled.');
        }
        const { featureName } = req.params;
        await this.featureLifecycleService.featureCompleted(featureName, req.audit);
        res.status(200).end();
    }
    async uncomplete(req, res) {
        if (!this.flagResolver.isEnabled('featureLifecycle')) {
            throw new error_1.NotFoundError('Feature lifecycle is disabled.');
        }
        const { featureName } = req.params;
        await this.featureLifecycleService.featureUnCompleted(featureName, req.audit);
        res.status(200).end();
    }
}
exports.default = FeatureLifecycleController;
//# sourceMappingURL=feature-lifecycle-controller.js.map