package com.hwrj.cloud.portal.controller;

import com.hwrj.cloud.common.api.CommonPage;
import com.hwrj.cloud.common.api.CommonResult;
import com.hwrj.cloud.portal.domain.BrandVO;
import com.hwrj.cloud.portal.domain.UmsCompanyInfoDto;
import com.hwrj.cloud.portal.domain.UmsMemberOriginDto;
import com.hwrj.cloud.portal.model.PmsProduct;
import com.hwrj.cloud.portal.model.UmsCompanyInfo;
import com.hwrj.cloud.portal.service.PmsPortalProductService;
import com.hwrj.cloud.portal.service.UmsCompanyInfoService;
import com.hwrj.cloud.portal.service.UmsMemberOriginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("company")
@Api(tags = "供应商信息",description = "UmsCompanyInfoController")
public class UmsCompanyInfoController {
    @Autowired
    private UmsCompanyInfoService umsCompanyInfoService;

    @Autowired
    private UmsMemberOriginService umsMemberOriginService;

    @Autowired
    private PmsPortalProductService productService;

    @ApiOperation("获取供应商详情")
    @GetMapping("/cp/detail")
    public CommonResult detail(@RequestParam(value = "compId",required = true)Long compId){
        UmsCompanyInfoDto infoDto = umsCompanyInfoService.detailInfo(compId);
        List<UmsMemberOriginDto> umsMemberOriginDtos = umsMemberOriginService.detailListOfCompany(infoDto.getId());
        infoDto.setOrigines(umsMemberOriginDtos);
        List<PmsProduct> productByCompanyId = productService.getProductByCompanyId(infoDto.getId());
        infoDto.setProducts(productByCompanyId);
        List<BrandVO> brands= productService.getPmsPrands(compId);
        infoDto.setBrands(brands);
        return CommonResult.success(infoDto);
    }
    @ApiOperation("搜索供应商列表")
    @GetMapping("/cp/search")
    public CommonResult search(@RequestParam(value = "key",required = false)String key){
        List<UmsCompanyInfo> infos = umsCompanyInfoService.searchCompanyInfo(key);
        return CommonResult.success(infos);
    }

    @ApiOperation("搜索供应商列表")
    @GetMapping("/cp/page")
    public CommonResult<CommonPage<UmsCompanyInfoDto>> search(@RequestParam(value = "key",required = false)String key,
                                           @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                           @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        List<UmsCompanyInfoDto> infos = umsCompanyInfoService.searchCompanyInfo(key,pageNum,pageSize);
        return CommonResult.success(CommonPage.restPage(infos));
    }

    @ApiOperation("获取生产地")
    @GetMapping("/cp/origin")
    public CommonResult searchOrigin(@RequestParam(value = "compId",required = true)Long compId){
        List<UmsMemberOriginDto> umsMemberOriginDtos = umsMemberOriginService.detailListOfCompany(compId);
        return CommonResult.success(umsMemberOriginDtos);
    }


}
