"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.GroupsController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const groups_service_1 = require("./groups.service");
const create_group_dto_1 = require("./dto/create-group.dto");
const update_group_dto_1 = require("./dto/update-group.dto");
const invite_member_dto_1 = require("./dto/invite-member.dto");
const group_response_dto_1 = require("./dto/group-response.dto");
const invite_response_dto_1 = require("./dto/invite-response.dto");
const current_user_decorator_1 = require("../../common/decorators/current-user.decorator");
const group_roles_decorator_1 = require("../../common/decorators/group-roles.decorator");
const enums_1 = require("../../common/enums");
const group_member_guard_1 = require("../../common/guards/group-member.guard");
const group_roles_guard_1 = require("../../common/guards/group-roles.guard");
let GroupsController = class GroupsController {
    constructor(groupsService) {
        this.groupsService = groupsService;
    }
    listMyGroups(user) {
        return this.groupsService.listMyGroups(user.id);
    }
    createGroup(user, dto) {
        return this.groupsService.createGroup(user.id, dto);
    }
    getGroup(id) {
        return this.groupsService.getGroup(id);
    }
    updateGroup(id, dto) {
        return this.groupsService.updateGroup(id, dto);
    }
    deleteGroup(id) {
        return this.groupsService.deleteGroup(id);
    }
    listMembers(id) {
        return this.groupsService.listMembers(id);
    }
    inviteMember(id, dto, user) {
        return this.groupsService.inviteMember(id, dto, user.id);
    }
    listInvites(id) {
        return this.groupsService.listPendingInvites(id);
    }
    cancelInvite(id, inviteId) {
        return this.groupsService.cancelInvite(id, inviteId);
    }
    removeMember(id, userId, user) {
        return this.groupsService.removeMember(id, userId, user.id);
    }
    leaveGroup(id, user) {
        return this.groupsService.leaveGroup(id, user.id);
    }
    getBalances(id) {
        return this.groupsService.getBalances(id);
    }
};
exports.GroupsController = GroupsController;
__decorate([
    (0, common_1.Get)(),
    (0, swagger_1.ApiOperation)({ summary: 'List all groups I belong to' }),
    (0, swagger_1.ApiResponse)({ status: 200, type: [group_response_dto_1.GroupDto] }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "listMyGroups", null);
__decorate([
    (0, common_1.Post)(),
    (0, swagger_1.ApiOperation)({ summary: 'Create a new group' }),
    (0, swagger_1.ApiResponse)({ status: 201, type: group_response_dto_1.GroupDetailDto }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, create_group_dto_1.CreateGroupDto]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "createGroup", null);
__decorate([
    (0, common_1.Get)(':id'),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'Get group details' }),
    (0, swagger_1.ApiResponse)({ status: 200, type: group_response_dto_1.GroupDetailDto }),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "getGroup", null);
__decorate([
    (0, common_1.Patch)(':id'),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard, group_roles_guard_1.GroupRolesGuard),
    (0, group_roles_decorator_1.GroupRoles)(enums_1.GroupRole.Admin),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'Update group (admin only)' }),
    (0, swagger_1.ApiResponse)({ status: 200, type: group_response_dto_1.GroupDetailDto }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, update_group_dto_1.UpdateGroupDto]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "updateGroup", null);
__decorate([
    (0, common_1.Delete)(':id'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard, group_roles_guard_1.GroupRolesGuard),
    (0, group_roles_decorator_1.GroupRoles)(enums_1.GroupRole.Admin),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'Delete group (admin only)' }),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "deleteGroup", null);
__decorate([
    (0, common_1.Get)(':id/members'),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'List group members' }),
    (0, swagger_1.ApiResponse)({ status: 200, type: [group_response_dto_1.MemberDto] }),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "listMembers", null);
__decorate([
    (0, common_1.Post)(':id/members'),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'Invite a member by email. Creates pending invite if they have no account.' }),
    (0, swagger_1.ApiResponse)({ status: 201, type: invite_response_dto_1.InviteResultDto }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, invite_member_dto_1.InviteMemberDto, Object]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "inviteMember", null);
__decorate([
    (0, common_1.Get)(':id/invites'),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard, group_roles_guard_1.GroupRolesGuard),
    (0, group_roles_decorator_1.GroupRoles)(enums_1.GroupRole.Admin),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'List pending invites (admin only)' }),
    (0, swagger_1.ApiResponse)({ status: 200, type: [invite_response_dto_1.PendingInviteDto] }),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "listInvites", null);
__decorate([
    (0, common_1.Delete)(':id/invites/:inviteId'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard, group_roles_guard_1.GroupRolesGuard),
    (0, group_roles_decorator_1.GroupRoles)(enums_1.GroupRole.Admin),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiParam)({ name: 'inviteId' }),
    (0, swagger_1.ApiOperation)({ summary: 'Cancel a pending invite (admin only)' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Param)('inviteId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "cancelInvite", null);
__decorate([
    (0, common_1.Delete)(':id/members/:userId'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard, group_roles_guard_1.GroupRolesGuard),
    (0, group_roles_decorator_1.GroupRoles)(enums_1.GroupRole.Admin),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiParam)({ name: 'userId' }),
    (0, swagger_1.ApiOperation)({ summary: 'Remove a member (admin only)' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Param)('userId')),
    __param(2, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "removeMember", null);
__decorate([
    (0, common_1.Post)(':id/leave'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'Leave the group' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "leaveGroup", null);
__decorate([
    (0, common_1.Get)(':id/balances'),
    (0, common_1.UseGuards)(group_member_guard_1.GroupMemberGuard),
    (0, swagger_1.ApiParam)({ name: 'id' }),
    (0, swagger_1.ApiOperation)({ summary: 'Get balance summary for all members' }),
    (0, swagger_1.ApiResponse)({ status: 200, type: [group_response_dto_1.BalanceEntryDto] }),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], GroupsController.prototype, "getBalances", null);
exports.GroupsController = GroupsController = __decorate([
    (0, swagger_1.ApiTags)('Groups'),
    (0, swagger_1.ApiBearerAuth)(),
    (0, common_1.Controller)({ path: 'groups', version: '1' }),
    __metadata("design:paramtypes", [groups_service_1.GroupsService])
], GroupsController);
//# sourceMappingURL=groups.controller.js.map