import { Public } from '../auth/public.decorator'
import { MembershipService } from './membership.service'
import { Body, Controller, Delete, Get, Param, Post, Put, Req } from '@nestjs/common'
import { MemberPlanDto } from './dto/memberPlan.dto'
import { HasRoles } from '../auth/roles.decorator'
import { Role } from '../model/role.enum'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { PageRequest } from '../common/dto/page-request'
import { MemberPlan } from './entities/memberPlan.entity'
import { Membership } from './entities/membership.entity'
import { MemberOrder } from './entities/member-order.entity'

@ApiTags('membership.admin')
@Controller('/admin/membership')
@ApiBearerAuth()
@HasRoles(Role.Admin)
export class MembershipAdminController {
    constructor(private readonly membershipService: MembershipService) {}

    @Post('/members')
    public async listMembers(@Body() page: PageRequest<Membership>) {
        return await this.membershipService.findAllMembers(page)
    }

    @Put('/plans')
    async savePlan(@Body() memberPlanDto: MemberPlanDto) {
        return await this.membershipService.savePlan(memberPlanDto)
    }

    @Delete('/plans/:id')
    async deletePlan(@Param('id') id: number) {
        return await this.membershipService.deletePlanById(id)
    }

    @Post('/orders')
    public async orders(@Body() page: PageRequest<MemberOrder>) {
        return await this.membershipService.findAllOrders(page)
    }
}
