package com.gree.mall.miniapp.controller.engin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.miniapp.bean.engin.RpProjectRepairBean;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.engin.ProjectRepairLogic;
import com.gree.mall.miniapp.plus.entity.RpProjectRepair;
import com.gree.mall.miniapp.plus.entity.RpProjectRepairProduct;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

@Slf4j
@RestController
@Api(value = "工程维保API", tags = {"工程维保API"})
@Validated
@RequestMapping(value = "/engin/project/repair", produces = "application/json; charset=utf-8")
public class ProjectRepairController {

    @Resource
    ProjectRepairLogic projectRepairLogic;

    @PostMapping("/list")
    @ApiOperation(value = "工程维保-列表")
    public ResponseHelper<Page<RpProjectRepair>> list(
            @RequestParam(required = false) String id,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize
    ) {
        IPage<RpProjectRepair> list = projectRepairLogic.list(id, pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "工程维保-详情")
    public ResponseHelper<RpProjectRepairBean> detail(
            @ApiParam(value = "id", required = true)   @RequestParam(required = true) String id
    ) throws RemoteServiceException {
        RpProjectRepairBean detail = projectRepairLogic.detail(id);
        return ResponseHelper.success(detail);
    }

    @PostMapping("/brand")
    @ApiOperation("工程维保-品牌(已去重)")
    public ResponseHelper<List<RpProjectRepairProduct>> brand(
            @ApiParam(value = "维保id",required = true) @RequestParam String repairProjectId
    ){
        List<RpProjectRepairProduct> brands = projectRepairLogic.brand(repairProjectId);
        return ResponseHelper.success(brands);
    }

    @PostMapping("/main")
    @ApiOperation("工程维保-大类(已去重)")
    public ResponseHelper<List<RpProjectRepairProduct>> main(
            @ApiParam(value = "维保id",required = true) @RequestParam String repairProjectId,
            @ApiParam(value = "品牌id",required = false) @RequestParam String brandId
    ){
        List<RpProjectRepairProduct> mains = projectRepairLogic.main(repairProjectId, brandId);
        return ResponseHelper.success(mains);
    }

    @PostMapping("/small")
    @ApiOperation("工程维保-小类(已去重)")
    public ResponseHelper<List<RpProjectRepairProduct>> small(
            @ApiParam(value = "维保id",required = true) @RequestParam String repairProjectId,
            @ApiParam(value = "品牌id",required = false) @RequestParam(required = false) String brandId,
            @ApiParam(value = "大类id",required = false) @RequestParam(required = false) String mainId
    ){
        List<RpProjectRepairProduct> small = projectRepairLogic.small(repairProjectId, brandId, mainId);
        return ResponseHelper.success(small);
    }

}
