import { PageQueryVo, ResultVo, TestAdminVo } from '@/model/vo';
import { TestService } from '@/service';
import { HPSFIR_CONTROLLER_METHOD_E, Context, Controller, InBody, InQuery, RequestMapping } from 'hpsfir-controller';
import { AutoWrite, HpsfirIoCContext } from 'hpsfir-ioc';
import { Log, Logger } from 'hpsfir-log';

@Controller('/test', { tag: { name: 'test', description: 'test管理' } })
export class TestController {

  @AutoWrite()
  private testService!: TestService;

  @Log(Symbol(TestController.name))
  private logger!: Logger;

  @RequestMapping('/listTest', {
    title: '获取test列表',
    method: HPSFIR_CONTROLLER_METHOD_E.POST,
  })
  async listTest(
    @InBody() conditions: Partial<TestAdminVo>,
    @Context() ctx?: HpsfirIoCContext,
  ): Promise<ResultVo<TestAdminVo[]>> {
    const res = await this.testService.listTest(conditions, ctx);
    return new ResultVo(true, '成功', res);
  }

  @RequestMapping('/pageTest', {
    title: '获取test列表(分页)',
    method: HPSFIR_CONTROLLER_METHOD_E.POST,
  })
  async pageTest(
    @InBody() conditions: Partial<TestAdminVo>,
    @InBody() pageQuery: PageQueryVo,
    @Context() ctx?: HpsfirIoCContext,
  ): Promise<ResultVo> {
    const res = await this.testService.pageTest(conditions, pageQuery, ctx);
    return new ResultVo(true, '成功', res);
  }

  @RequestMapping('/addTest', {
    title: '添加test',
    method: HPSFIR_CONTROLLER_METHOD_E.POST,
  })
  async addTest(
    @InBody() testAdminVo: TestAdminVo,
    @Context() ctx?: HpsfirIoCContext,
  ): Promise<ResultVo> {
    await this.testService.addTest(testAdminVo, ctx);
    return new ResultVo(true, '添加成功');
  }

  @RequestMapping('/updateTest', {
    title: '更新test',
    method: HPSFIR_CONTROLLER_METHOD_E.PUT,
  })
  async updateTest(
    @InBody() testAdminVo: Partial<TestAdminVo>,
    @Context() ctx?: HpsfirIoCContext,
  ): Promise<ResultVo> {
    await this.testService.updateTest(testAdminVo, ctx);
    return new ResultVo(true, '更新成功');
  }

  @RequestMapping('/delTest', {
    title: '删除test',
    method: HPSFIR_CONTROLLER_METHOD_E.DELETE,
  })
  async delTest(
    @InQuery() testId: number,
    @Context() ctx?: HpsfirIoCContext,
  ): Promise<ResultVo> {
    await this.testService.delTest(testId, ctx);
    return new ResultVo(true, '删除成功');
  }

}
