import { Provide, Inject, Controller, Post, Get, Body, Query } from '@midwayjs/core';
import { NetaClawAgentChannelService } from '../../service/agent_channel.js';

@Provide()
@Controller('/admin/netaclaw/agent_channel')
export class NetaClawAgentChannelAdminController {
  @Inject()
  channelService: NetaClawAgentChannelService;

  @Post('/page')
  async page(
    @Body()
    body: { page?: number; size?: number; keyWord?: string; type?: string; loginStatus?: string }
  ) {
    return { code: 1000, data: await this.channelService.page(body) };
  }

  @Post('/add')
  async add(@Body() body: any) {
    return { code: 1000, data: await this.channelService.add(body) };
  }

  @Post('/update')
  async update(@Body() body: any) {
    await this.channelService.update(body);
    return { code: 1000, message: 'success' };
  }

  @Post('/delete')
  async delete(@Body() body: { ids: number[] }) {
    await this.channelService.delete(body.ids);
    return { code: 1000, message: 'success' };
  }

  @Get('/info')
  async info(@Query('id') id: number) {
    return { code: 1000, data: await this.channelService.info(id) };
  }

  @Get('/options')
  async options() {
    return { code: 1000, data: await this.channelService.options() };
  }

  @Post('/weixin/qr')
  async createWeixinQr(@Body('id') id: number) {
    return { code: 1000, data: await this.channelService.createWeixinQr(id) };
  }

  @Post('/weixin/qr/status')
  async pollWeixinQr(@Body('id') id: number) {
    return { code: 1000, data: await this.channelService.pollWeixinQr(id) };
  }

  @Post('/disconnect')
  async disconnect(@Body('id') id: number) {
    await this.channelService.disconnect(id);
    return { code: 1000, message: 'success' };
  }

  @Post('/restart')
  async restart(@Body('id') id: number) {
    await this.channelService.restart(id);
    return { code: 1000, message: 'success' };
  }

  @Post('/clearSessions')
  async clearSessions(@Body('id') id: number) {
    return { code: 1000, data: await this.channelService.clearSessions(id) };
  }
}
