package com.trade.client.companyrelated.controller;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import com.trade.common.core.domain.ResponseResult;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.trade.client.companyrelated.service.VendorEntityCService;
import com.trade.service.companyrelated.domain.VendorEntity;
import com.trade.service.companyrelated.domain.vo.VendorEntitySearch;

/**
 * <p>
 * 供应商企业信息 C端前端控制器
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-03
 */
@Controller
@RequestMapping("/vendorEntity")
public class VendorEntityController {

    @Resource
    private VendorEntityCService vendorEntityCService;

    /**
     * 获取供应商信息列表
     */
    @RequestMapping("/queryList")
    public Object queryList(VendorEntitySearch search) {
        return ResponseResult.success(vendorEntityCService.queryListBySearch(search));
    }

    /**
     * 保存供应商信息
     */
    @RequestMapping("/add")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseResult<Void> add(@RequestBody @Valid VendorEntity addEntity) {
        vendorEntityCService.add(addEntity);
        return ResponseResult.success();
    }

    /**
     * 更新供应商信息
     */
    @RequestMapping("/update")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseResult<Void> update(@RequestBody @Valid VendorEntity addEntity) {
        vendorEntityCService.update(addEntity);
        return ResponseResult.success();
    }

    /**
     * 根据用户ID获取供应商信息列表
     */
    @RequestMapping("/getByUserId")
    public Object getRelatedListByUserId(@NotNull(message = "用户ID不能为空") Long userId) {
        return ResponseResult.success(vendorEntityCService.getListByUserId(userId));
    }

    /**
     * 根据供应商ID获取供应商信息
     */
    @RequestMapping("/getByEntityId")
    public Object getByEntityId(@NotNull(message = "供应商ID不能为空") Long entityId) {
        return ResponseResult.success(vendorEntityCService.getByEntityId(entityId));
    }
}
