import { Body, Inject, Post, Provide } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { NetaClawCrewEntity } from '../../entity/crew.js';
import { CrewService } from '../../service/crew.js';

@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: NetaClawCrewEntity,
  pageQueryOp: {
    fieldEq: ['status'],
    keyWordLikeFields: ['name', 'label'],
  },
})
export class AdminCrewController extends BaseController {
  @Inject()
  crewService: CrewService;

  @Post('/saveCanvas')
  async saveCanvas(@Body() body: any) {
    const { crewId, canvasData, members, delegateHints, masterAgentId } = body;
    await this.crewService.saveCanvas(crewId, { canvasData, members, delegateHints, masterAgentId });
    return this.ok();
  }

  @Post('/detail')
  async detail(@Body() body: any) {
    const result = await this.crewService.getDetail(body.id);
    return this.ok(result);
  }

  @Post('/publish')
  async publish(@Body() body: any) {
    await this.crewService.publish(body.id);
    return this.ok();
  }

  @Post('/unpublish')
  async unpublish(@Body() body: any) {
    await this.crewService.unpublish(body.id);
    return this.ok();
  }
}
