import { Body, Controller, Get, Post, Query } from '@nestjs/common'
import { WeixinService } from './weixin.service'
import { Public } from '../auth/public.decorator'
import { ApiQuery, ApiTags } from '@nestjs/swagger'

@ApiTags('weixin')
@Controller('/weixin')
export class WeixinController {
    constructor(private readonly weixinService: WeixinService) {}

    @Get('/accessToken')
    public async getAccessToken() {
        return await this.weixinService.getAccessToken()
    }

    @Public()
    @Post('/redirectUrl')
    @ApiQuery({ name: 'url' })
    public getRedirectUrl(@Body() { url, state }) {
        return { url: this.weixinService.getRedirectUrl(url, state) }
    }

    @Public()
    @Get('/code2openid')
    public async code2openid(@Query() { code }) {
        return await this.weixinService.code2oenId(code)
    }

    @Public()
    @Post('/jsapiSign')
    public async jsapiSign(@Body() { url }) {
        return await this.weixinService.jsapiSign(url)
    }
}
