package com.njzscloud.supervisory.biz.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.supervisory.biz.constant.AuditStatus;
import com.njzscloud.supervisory.biz.pojo.entity.BizTruckEntity;
import com.njzscloud.supervisory.biz.pojo.param.ModifyBizTruckParam;
import com.njzscloud.supervisory.biz.pojo.param.SearchTruckParam;
import com.njzscloud.supervisory.biz.pojo.result.SearchTruckResult;
import com.njzscloud.supervisory.biz.service.BizTruckService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆信息
 */
@Slf4j
@RestController
@RequestMapping("/biz_truck")
@RequiredArgsConstructor
public class BizTruckController {

    private final BizTruckService bizTruckService;

    /**
     * 新增
     *
     * @param bizTruckEntity 数据
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody BizTruckEntity bizTruckEntity) {
        bizTruckService.add(bizTruckEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody ModifyBizTruckParam modifyBizTruckParam) {
        bizTruckService.modify(modifyBizTruckParam);
        return R.success();
    }

    /**
     * 审核
     *
     * @param id Id
     */
    @GetMapping("/audit")
    public R<?> audit(@RequestParam Long id,
                      @RequestParam AuditStatus auditStatus,
                      @RequestParam(required = false, defaultValue = "") String auditMemo,
                      @RequestParam(required = false, defaultValue = "") List<String> certificationDate) {
        bizTruckService.audit(id, auditStatus, auditMemo, certificationDate);
        return R.success();
    }

    /**
     * 删除
     *
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        bizTruckService.del(ids);
        return R.success();
    }

    /**
     * 详情
     *
     * @param id Id
     * @return BizTruckEntity 结果
     */
    @GetMapping("/detail")
    public R<SearchTruckResult> detail(@RequestParam Long id) {
        return R.success(bizTruckService.detail(id));
    }

    /**
     * 分页查询
     *
     * @param searchTruckParam 筛选条件
     * @param pageParam        分页参数
     * @return PageResult&lt;SearchTruckResult&gt; 分页结果
     */
    @GetMapping("/paging")
    public R<PageResult<SearchTruckResult>> paging(PageParam pageParam, SearchTruckParam searchTruckParam) {
        return R.success(bizTruckService.paging(pageParam, searchTruckParam));
    }

    /**
     * 可分配车辆列表
     *
     * @param pageParam 分页参数
     * @param keywords  关键字
     * @return PageResult&lt;BizTruckEntity&gt; 分页结果
     */
    @GetMapping("/dispensability")
    public R<PageResult<BizTruckEntity>> dispensabilityList(PageParam pageParam, @RequestParam(required = false) String keywords) {
        return R.success(bizTruckService.dispensabilityList(pageParam, keywords));
    }

    /**
     * 撤销
     *
     * @param id Id
     */
    @GetMapping("/cancel")
    public R<?> cancel(@RequestParam Long id) {
        bizTruckService.cancel(id);
        return R.success();
    }

    /**
     * 切换公司
     *
     * @param companyId Id
     */
    @GetMapping("/change_company")
    public R<?> changeCompany(@RequestParam Long id,
                              @RequestParam Long companyId
    ) {
        bizTruckService.changeCompany(id, companyId);
        return R.success();
    }
}
