package com.crm.manager.controller;

import com.crm.manager.service.SalesCommissionManualService;
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.sales.SalesCommissionManualDto;
import com.crm.rely.backend.core.dto.sales.SalesCommissionManualSalaryTypeDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.login.InfoEntity;
import com.crm.rely.backend.core.entity.sales.SalesCommissionManualAddEntity;
import com.crm.rely.backend.core.entity.sales.SalesCommissionManualListEntity;
import com.crm.rely.backend.core.entity.sales.SalesCommissionManualUpdateEntity;
import com.crm.rely.backend.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
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("/sales/commission/manual")
public class SalesCommissionManualController {

    @Autowired
    private SalesCommissionManualService salesCommissionManualService;


    @PostMapping("/salaryTypes")
    public BaseResultDto<List<SalesCommissionManualSalaryTypeDto>> salaryTypes() throws ServiceException {
        return BaseResultDto.success(salesCommissionManualService.getSalesCommissionManualSalaryTypes());
    }

    @PostMapping("/add")
    public BaseResultDto<Object> add(@RequestBody SalesCommissionManualAddEntity entity) throws ServiceException {
        salesCommissionManualService.saveForm(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/update")
    public BaseResultDto<Object> update(@RequestBody SalesCommissionManualUpdateEntity entity) throws ServiceException {
        salesCommissionManualService.updateForm(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/delete")
    public BaseResultDto<Object> delete(@RequestBody SingleLongEntity entity, InfoEntity infoEntity) throws ServiceException {
        salesCommissionManualService.deleteById(entity.getId());
        return BaseResultDto.success();
    }

    @PostMapping("/search/single")
    public BaseResultDto<SalesCommissionManualDto> searchSingle(@RequestBody SingleLongEntity entity, InfoEntity infoEntity) throws ServiceException {
        return BaseResultDto.success(salesCommissionManualService.searchSingle(entity.getId()));
    }

    @PostMapping("/search/list")
    public BaseResultWithPagerDto<List<SalesCommissionManualDto>> searchList(@RequestBody SalesCommissionManualListEntity entity) throws ServiceException {
        return salesCommissionManualService.searchList(entity);
    }

}
