import {
  CoolController,
  BaseController,
  CoolUrlTag,
  TagTypes,
  CoolTag,
} from '@cool-midway/core';
import { Body, Inject, Post } from '@midwayjs/core';
import { ShopSorterService } from '../../service/sorter';

/**
 * 分拣员 App
 */
@CoolUrlTag()
@CoolController()
export class AppShopSorterController extends BaseController {
  @Inject()
  shopSorterService: ShopSorterService;

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/checkUser', { summary: '扫描回收码校验平台用户' })
  async checkUser(@Body('unionid') unionid: string) {
    return this.ok(await this.shopSorterService.checkUser(unionid));
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/checkIn', { summary: '打卡积分' })
  async checkIn(
    @Body() body: { unionid: string; sorterId: string }
  ) {
    return this.ok(await this.shopSorterService.checkIn(body));
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/itemList', { summary: '回收品类列表' })
  async itemList(@Body('sorterId') sorterId: string) {
    return this.ok(await this.shopSorterService.itemList(sorterId));
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/saveOrder', { summary: '保存现场或预约回收清单' })
  async saveOrder(
    @Body()
    body: {
      sorterId: string;
      unionid: string;
      appointmentId?: number;
      items: any[];
    }
  ) {
    return this.ok(await this.shopSorterService.saveOrder(body));
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/appointmentPage', { summary: '预约回收订单分页' })
  async appointmentPage(@Body() body) {
    return this.ok(await this.shopSorterService.appointmentPage(body));
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/confirmAppointment', { summary: '确认预约单' })
  async confirmAppointment(
    @Body() body: { id: number; sorterId: string }
  ) {
    return this.ok(await this.shopSorterService.confirmAppointment(body));
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/claimAppointment', { summary: '领取预约单到自己名下' })
  async claimAppointment(
    @Body() body: { id: number; sorterId: string }
  ) {
    return this.ok(await this.shopSorterService.claimAppointment(body));
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/scanAppointment', { summary: '扫描预约单' })
  async scanAppointment(
    @Body('appointmentNo') appointmentNo: string,
    @Body('sorterId') sorterId: string
  ) {
    return this.ok(
      await this.shopSorterService.scanAppointment(appointmentNo, sorterId)
    );
  }
}
