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.pojo.entity.BizDriverEntity;
import com.njzscloud.supervisory.biz.pojo.param.AddDriverParam;
import com.njzscloud.supervisory.biz.pojo.param.AuditDriverParam;
import com.njzscloud.supervisory.biz.pojo.param.ModifyDriverParam;
import com.njzscloud.supervisory.biz.service.BizDriverService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 司机信息
 */
@Slf4j
@RestController
@RequestMapping("/biz_driver")
@RequiredArgsConstructor
public class BizDriverController {

    private final BizDriverService bizDriverService;

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

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody ModifyDriverParam modifyDriverParam) {
        bizDriverService.modify(modifyDriverParam);
        return R.success();
    }

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

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

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

    /**
     * 查询可用的司机
     */
    @GetMapping("/dispensability")
    public R<PageResult<BizDriverEntity>> dispensabilityList(PageParam pageParam, @RequestParam(required = false) String keywords) {
        return R.success(bizDriverService.dispensabilityList(pageParam, keywords));
    }

    /**
     * 审核司机
     *
     * @param auditDriverParam 审核参数
     */
    @PostMapping("/audit")
    public R<?> audit(@RequestBody AuditDriverParam auditDriverParam) {
        bizDriverService.audit(auditDriverParam);
        return R.success();
    }

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

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