package com.bonus.material.lease.controller;

import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.lease.domain.MaLease;
import com.bonus.material.lease.domain.MaLeaseDto;
import com.bonus.material.lease.domain.MaLeaseInfo;
import com.bonus.material.lease.domain.vo.MaLeaseVo;
import com.bonus.material.lease.service.MaLeaseInfoService;
import com.bonus.material.order.domain.OrderDetailDto;
import com.bonus.material.order.domain.OrderInfoDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author ma_sh
 * @create 2024/11/26 10:40
 */
@Api(value = "租赁需求大厅控制层")
@RestController
@RequestMapping("/ma-lease")
public class MaLeaseInfoController extends BaseController {

    @Resource
    private MaLeaseInfoService leaseInfoService;

    /**
     * 查询租赁需求列表(后台)
     * @param dto
     * @return
     */
    @ApiOperation(value = "查询租赁需求列表")
    @GetMapping("/list")
    public AjaxResult list(MaLeaseDto dto) {
        startPage();
        List<MaLeaseVo> list = leaseInfoService.list(dto);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 查询租赁需求列表首页
     * @param maLease
     * @return
     */
    @ApiOperation(value = "查询租赁需求列表首页")
    @PostMapping("/leaseList")
    public AjaxResult leaseList(@RequestBody MaLease maLease) {
        List<MaLeaseVo> list = leaseInfoService.leaseList(maLease);
        Integer pageIndex = Convert.toInt(maLease.getPageNum(), 1);
        Integer pageSize = Convert.toInt(maLease.getPageSize(), 10);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    @ApiOperation(value = "获取单个订单详情")
    @GetMapping("/getLeaseStatusCount")
    public AjaxResult getOrderStatusCount(MaLeaseInfo dto) {
        List<MaLeaseInfo> list = leaseInfoService.getLeaseStatusCount(dto);
        return success(list);
    }

    /**
     * 查询出租方需求列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "查询出租方需求列表")
    @GetMapping("/rentList")
    public AjaxResult rentList(MaLeaseDto dto) {
        startPage();
        List<MaLeaseVo> list = leaseInfoService.rentList(dto);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 发布租赁需求
     * @param maLeaseInfo
     * @return
     */
    @ApiOperation(value = "发布租赁需求")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MaLeaseInfo maLeaseInfo) {
        return leaseInfoService.add(maLeaseInfo);
    }

    /**
     * 查询单个租赁需求详情
     * @param maLeaseInfo
     * @return
     */
    @ApiOperation(value = "查询单个租赁需求详情")
    @GetMapping("/getById")
    public AjaxResult getById(MaLeaseInfo maLeaseInfo) {
        return leaseInfoService.getById(maLeaseInfo);
    }

    /**
     * 修改租赁需求
     * @param maLeaseInfo
     * @return
     */
    @ApiOperation(value = "修改租赁需求")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody MaLeaseInfo maLeaseInfo) {
        return leaseInfoService.edit(maLeaseInfo);
    }

    /**
     * 出租方立即接单
     * @param maLeaseInfo
     * @return
     */
    @ApiOperation(value = "出租方立即接单")
    @PostMapping("/accept")
    public AjaxResult accept(@RequestBody MaLeaseInfo maLeaseInfo) {
        return leaseInfoService.accept(maLeaseInfo);
    }

    @ApiOperation(value = "承租方审核（同意或驳回）")
    @PostMapping("/audit")
    public AjaxResult agreeOrReject(@RequestBody MaLeaseInfo maLeaseInfo) {
        return leaseInfoService.agreeOrReject(maLeaseInfo);
    }

    /**
     * 删除租赁需求
     * @param maLeaseInfo
     * @return
     */
    @ApiOperation(value = "删除租赁需求")
    @PostMapping("/deleteById")
    public AjaxResult deleteById(@RequestBody MaLeaseInfo maLeaseInfo) {
        return leaseInfoService.deleteById(maLeaseInfo);
    }
}
