package com.trade.client.enterprise.companyrelated.controller;

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

import com.trade.client.enterprise.companyrelated.service.VendorEntityCService;
import com.trade.client.security.utils.UserUtils;
import com.trade.common.core.domain.ResponseResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.trade.service.enterprise.companyrelated.domain.VendorEntity;
import com.trade.service.enterprise.companyrelated.domain.vo.VendorEntitySearch;
import org.springframework.web.bind.annotation.RestController;

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

    @Resource
    private VendorEntityCService vendorEntityCService;

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

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

    /**
     * 更新供应商信息
     */
    @RequestMapping("/update")
    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));
    }
}
