package com.jwipc.order.controller.pc;

import com.alibaba.fastjson2.JSON;
import com.jwipc.order.dto.AppointmentTimeDTO;
import com.jwipc.order.logic.AppointmentTimeLogic;
import com.jwipc.order.model.query.AppointmentRecordQuery;
import com.jwipc.order.model.query.AppointmentTimeQuery;
import com.jwipc.page.PageView;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.jwipc.order.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>
 *预约时间范围数据配置
 * </p>
 *
 * @author wt
 * @version 1.0
 * @since 2024/3/5
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(MODULE_ROOT + "/appointmentTime/rest")
public class AppointmentTimeRestController {

    private final AppointmentTimeLogic appointmentTimeLogic;

    /**
     * 查询预约时间范围数据配置列表
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public ResponseEntity<?> list(AppointmentTimeQuery query){
        PageView pageView = appointmentTimeLogic.getList(query);
        return ResponseEntity.ok(pageView);
    }

    /**
     * 时间范围选择器
     * @param query
     * @return
     */
    @RequestMapping("/selector")
    public List<AppointmentTimeDTO> selectorList(AppointmentTimeQuery query) {
        return appointmentTimeLogic.selectorList(query);
    }

    /**
     *新增&编辑数据
     * @param data
     * @return
     */
    @RequestMapping("/save")
    public ResponseEntity<?> save(String data){
        AppointmentTimeDTO appointmentTimeDto = JSON.parseObject(data, AppointmentTimeDTO.class);
        appointmentTimeLogic.saveData(appointmentTimeDto);
        return ResponseEntity.ok("ok");
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @RequestMapping("/remove")
    public ResponseEntity<?> remove(Long id){
        appointmentTimeLogic.removeById(id);
        return ResponseEntity.ok("ok");
    }

    /**
     * 根据日期查询指定日期已经预约的数量
     *
     * @param query 查询条件
     * @return 结果
     */
    @PostMapping("/appointmentList")
    public ResponseEntity<?> provideEditDo(AppointmentRecordQuery query) {
        return ResponseEntity.ok(appointmentTimeLogic.getTimeRangeData(query));
    }
}
