import { Inject } from "@midwayjs/core";
import { CoolController, BaseController } from "@cool-midway/core";
import { RecycleAppointmentEntity } from "../../entity/recycleappointment";
import { RecycleAppointmentService } from "../../service/recycleappointment";

/**
 * 回收预约-应用端
 */
@CoolController({
  api: ["add", "info", "page"],
  entity: RecycleAppointmentEntity,
  service: RecycleAppointmentService,
  pageQueryOp: {
    fieldEq: ["a.status", "a.campusUserId"],
    addOrderBy: {
      createTime: "DESC",
    },
    where: async (ctx) => {
      const { tab } = ctx.request.body;
      if (tab === "done") {
        return [["a.status = :st", { st: "已完成" }]];
      }
      if (tab === "booked") {
        return [["a.status != :st", { st: "已完成" }]];
      }
      return [];
    },
  },
})
export class AppRecycleAppointmentController extends BaseController {
  @Inject()
  recycleAppointmentService: RecycleAppointmentService;
}
