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

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

import com.github.pagehelper.PageInfo;
import com.trade.client.security.utils.UserUtils;
import com.trade.common.core.domain.ResponseResult;
import com.trade.service.enterprise.companyrelated.domain.vo.ImporterEntityVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.trade.client.enterprise.companyrelated.service.ImporterEntityCService;
import com.trade.common.validate.OnCreate;
import com.trade.common.validate.OnUpdate;
import com.trade.service.enterprise.companyrelated.domain.ImporterEntity;
import com.trade.service.enterprise.companyrelated.domain.vo.ImporterEntitySearch;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 进口商企业信息 前端控制器
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-03
 */
@RestController
@RequestMapping("/importerEntity")
public class ImporterEntityController {

    @Resource
    private ImporterEntityCService importerEntityCService;

    /**
     * 获取进口商信息列表
     */
    @RequestMapping("/queryList")
    public ResponseResult<PageInfo<ImporterEntityVO>> queryList(ImporterEntitySearch search) {
        search.setCustomerUserId(UserUtils.getCustomerUserId());
        return ResponseResult.success(importerEntityCService.queryListBySearch(search));
    }

    /**
     * 提交进口商信息
     */
    @RequestMapping("/add")
    @Validated(OnCreate.class)
    public ResponseResult<Void> submit(@RequestBody @Valid ImporterEntity addEntity) {
        importerEntityCService.add(addEntity);
        return ResponseResult.success();
    }

    /**
     * 根据用户ID获取进口商信息列表
     */
    @RequestMapping("/getByUserId")
    public ResponseResult<List<ImporterEntity>> getRelatedListByUserId(@NotNull(message = "用户ID不能为空") Long userId) {
        return ResponseResult.success(importerEntityCService.getListByUserId(userId));
    }

    /**
     * 根据用户ID获取生效的进口商信息列表
     */
    @RequestMapping("/getEnabledByUserId")
    public ResponseResult<List<ImporterEntity>> getEnabledListByUserId(@NotNull(message = "用户ID不能为空") Long userId) {
        return ResponseResult.success(importerEntityCService.getEnabledListByUserId(userId));
    }

    /**
     * 修改进口商信息
     */
    @RequestMapping("/update")
    @Validated(OnUpdate.class)
    public ResponseResult<Void> update(@RequestBody @Valid ImporterEntity updateEntity) {
        importerEntityCService.update(updateEntity);
        return ResponseResult.success();
    }

    /**
     * 根据进口商ID获取进口商信息
     */
    @RequestMapping("/getByEntityId")
    public ResponseResult<ImporterEntityVO> getByEntityId(@NotNull(message = "进口商ID不能为空") Long entityId) {
        return ResponseResult.success(importerEntityCService.getByEntityId(entityId));
    }

    /**
     * 根据进口商ID获取进口商信息
     */
    @RequestMapping("/delete")
    public ResponseResult<Void> deleteByBizEntityId(@NotNull(message = "进口商ID不能为空") Long entityId) {
        importerEntityCService.deleteByEntityId(entityId);
        return ResponseResult.success();
    }
}
