package com.crm.manager.controller;

import com.crm.manager.service.SalesLeaderService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.core.dto.sales.SalesLeaderListDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.sales.SalesLeaderAddEntity;
import com.crm.rely.backend.core.entity.sales.SalesLeaderDeleteEntitys;
import com.crm.rely.backend.core.entity.sales.SalesLeaderSearchEntity;
import com.crm.rely.backend.core.entity.sales.SalesLeaderUpdateEntity;
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;

@RestController
@RequestMapping("/sales/leader")
public class SalesLeaderController {

    @Autowired
    private SalesLeaderService salesLeaderService;

    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated SalesLeaderAddEntity entity) throws Exception {
        salesLeaderService.add(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated SalesLeaderDeleteEntitys entitys) throws Exception {

        salesLeaderService.delete(entitys);
        return BaseResultDto.success();
    }

    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated SalesLeaderUpdateEntity entity) throws Exception {
        salesLeaderService.update(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/search/list")
    public ResultWithPagerDto<SalesLeaderListDto> pageList(@RequestBody SalesLeaderSearchEntity entity) throws Exception {

        return salesLeaderService.searchPageList(entity);
    }

    @PostMapping("/search/single")
    public BaseResultDto searchSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        SalesLeaderListDto result = salesLeaderService.searchSingle(entity);
        return BaseResultDto.success(result);
    }

    @PostMapping("/all/list")
    public BaseResultDto getAllList(@RequestBody SalesLeaderSearchEntity entity) throws Exception {
        return BaseResultDto.success(salesLeaderService.getAllList(entity));
    }

    @PostMapping("/search/add/ib")
    public BaseResultDto searchAddIbNo(@RequestBody SalesLeaderSearchEntity entity) throws Exception {
        return BaseResultDto.success(salesLeaderService.searchAddIbNo(entity));
    }

    @PostMapping("/add/ib")
    public BaseResultDto addSalesIbNo(@RequestBody @Validated SalesLeaderAddEntity entity) throws Exception {
        salesLeaderService.addSalesIbNo(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/delete/ib")
    public BaseResultDto deleteSalesIbNo(@RequestBody @Validated SalesLeaderAddEntity entity) throws Exception {
        salesLeaderService.deleteSalesIbNo(entity);
        return BaseResultDto.success();
    }

}
