"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.DevicesController = void 0;
const common_1 = require("@nestjs/common");
const current_user_decorator_1 = require("../../common/decorators/current-user.decorator");
const zod_validation_pipe_1 = require("../../common/pipes/zod-validation.pipe");
const jwt_guard_1 = require("../owner/guards/jwt.guard");
const devices_dto_1 = require("./devices.dto");
const devices_service_1 = require("./devices.service");
let DevicesController = class DevicesController {
    constructor(service) {
        this.service = service;
    }
    async requestChange(body, owner_id, req, res) {
        const user = req.user;
        const memberId = user?.sub || user?.id;
        const result = await this.service.requestDeviceChange(memberId, owner_id, body);
        return res.status(result.status).json(result);
    }
    async getMyDevice(owner_id, req, res) {
        const user = req.user;
        const memberId = user?.sub || user?.id;
        const result = await this.service.getMyDevice(memberId, owner_id);
        return res.status(result.status).json(result);
    }
    async getRequests(query, owner_id, res) {
        const result = await this.service.getDeviceChangeRequests(owner_id, query);
        return res.status(result.status).json(result);
    }
    async reviewRequest(id, body, owner_id, req, res) {
        const user = req.user;
        const reviewerId = user?.sub || user?.id;
        const result = await this.service.reviewDeviceChangeRequest(id, owner_id, reviewerId, body);
        return res.status(result.status).json(result);
    }
    async resetDevice(memberId, owner_id, res) {
        const result = await this.service.resetDeviceBinding(memberId, owner_id);
        return res.status(result.status).json(result);
    }
};
exports.DevicesController = DevicesController;
__decorate([
    (0, common_1.Post)('request-change'),
    (0, common_1.UsePipes)(new zod_validation_pipe_1.ZodValidationPipe(devices_dto_1.requestDeviceChangeSchema)),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, Object, Object]),
    __metadata("design:returntype", Promise)
], DevicesController.prototype, "requestChange", null);
__decorate([
    (0, common_1.Get)('my-device'),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __param(1, (0, common_1.Req)()),
    __param(2, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, Object]),
    __metadata("design:returntype", Promise)
], DevicesController.prototype, "getMyDevice", null);
__decorate([
    (0, common_1.Get)('requests'),
    (0, common_1.UsePipes)(new zod_validation_pipe_1.ZodValidationPipe(devices_dto_1.deviceChangeFilterSchema)),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __param(2, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, Object]),
    __metadata("design:returntype", Promise)
], DevicesController.prototype, "getRequests", null);
__decorate([
    (0, common_1.Patch)('requests/:id/review'),
    (0, common_1.UsePipes)(new zod_validation_pipe_1.ZodValidationPipe(devices_dto_1.reviewDeviceChangeSchema)),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, current_user_decorator_1.CurrentUser)()),
    __param(3, (0, common_1.Req)()),
    __param(4, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, String, Object, Object]),
    __metadata("design:returntype", Promise)
], DevicesController.prototype, "reviewRequest", null);
__decorate([
    (0, common_1.Delete)('reset/:memberId'),
    __param(0, (0, common_1.Param)('memberId')),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __param(2, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object]),
    __metadata("design:returntype", Promise)
], DevicesController.prototype, "resetDevice", null);
exports.DevicesController = DevicesController = __decorate([
    (0, common_1.Controller)('devices'),
    (0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
    __metadata("design:paramtypes", [devices_service_1.DevicesService])
], DevicesController);
//# sourceMappingURL=devices.controller.js.map