package com.crm.manager.controller;

import com.crm.manager.service.SysSalesLoginService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
import com.crm.rely.backend.core.dto.sys.SysSalesLoginDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.sys.SysSalesLoginAddEntity;
import com.crm.rely.backend.core.entity.sys.SysSalesLoginSearchListEntity;
import com.crm.rely.backend.core.entity.sys.SysSalesLoginUpdateEntity;
import com.crm.rely.backend.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sys/sales/login")
public class SysSalesLoginController {

    @Autowired
    private SysSalesLoginService sysSalesLoginService;

    @PostMapping("/add")
    public BaseResultDto<Object> add(@RequestBody @Validated SysSalesLoginAddEntity entity) throws ServiceException{
        sysSalesLoginService.add(entity);
        return BaseResultDto.success();
    }

//    @PostMapping("/addFromUserInfo")
//    public BaseResultDto<Object> addFromUserInfo(@RequestBody @Validated SysSalesLoginAddEntity entity) throws ServiceException{
//        sysSalesLoginService.addFromUserInfo(entity);
//        return BaseResultDto.success();
//    }

    @PostMapping("/update")
    public BaseResultDto<Object> update(@RequestBody @Validated SysSalesLoginUpdateEntity entity) throws ServiceException{
        sysSalesLoginService.update(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/delete")
    public BaseResultDto<Object> delete(@RequestBody @Validated SingleLongEntity entity) throws ServiceException{
        sysSalesLoginService.delete(entity.getId());
        return BaseResultDto.success();
    }

    @PostMapping("/search/single")
    public BaseResultDto<SysSalesLoginDto> searchSingle(@RequestBody SingleLongEntity entity) throws ServiceException{
        return BaseResultDto.success(sysSalesLoginService.searchSingle(entity.getId()));
    }

    @PostMapping("/search/list")
    public BaseResultWithPagerDto<List<SysSalesLoginDto>> searchList(@RequestBody SysSalesLoginSearchListEntity entity) throws ServiceException{
        return sysSalesLoginService.searchList(entity);
    }
}
