package com.jwipc.order.controller.pc;

import com.alibaba.fastjson2.JSON;
import com.jwipc.order.dto.AppointmentSupplierDTO;
import com.jwipc.order.logic.AppointmentSupplierLogic;
import com.jwipc.order.model.query.AppointmentSupplierQuery;
import com.jwipc.page.PageView;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 static com.jwipc.order.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>
 *  送货单预约供应商配置
 * </p>
 *
 * @author wt
 * @version 1.0
 * @since 2024/3/4
 */
@RestController
@RequestMapping(MODULE_ROOT + "/appointmentSupplier/rest")
@RequiredArgsConstructor
@Slf4j
public class AppointmentSupplierRestController {

    private final AppointmentSupplierLogic appointmentSupplierLogic;

    @RequestMapping("/list")
    public PageView list(AppointmentSupplierQuery query) {
        PageView pageView = appointmentSupplierLogic.getList(query);
        return pageView;
    }

    /**
     * 新增或编辑数据
     * @param data
     * @return
     */
    @PostMapping("/save")
    public ResponseEntity<?> saveData(String data){
        AppointmentSupplierDTO dto = JSON.parseObject(data, AppointmentSupplierDTO.class);
        appointmentSupplierLogic.saveData(dto);
        return ResponseEntity.ok("ok");
    }

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

    /**
     * 启用 禁用
     * @param id
     * @return
     */
    @RequestMapping("/updateStatus")
    public ResponseEntity<?> updateStatus(Long id){
        appointmentSupplierLogic.updateStatus(id);
        return ResponseEntity.ok("ok");
    }
}
