package com.crm.manager.controller;

import com.crm.manager.service.CustomLoginSpecialCalcService;
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.custom.login.special.CustomLoginSpecialCalcDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.custom.info.InfoEntity;
import com.crm.rely.backend.core.entity.custom.login.special.CustomLoginSpecialCalcAddEntity;
import com.crm.rely.backend.core.entity.custom.login.special.CustomLoginSpecialCalcListEntity;
import com.crm.rely.backend.core.entity.custom.login.special.CustomLoginSpecialCalcUpdateEntity;
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("/custom/login/special/calc")
public class CustomLoginSpecialCalcController {

    @Autowired
    private CustomLoginSpecialCalcService customLoginSpecialCalcService;

    @PostMapping("/add")
    public BaseResultDto<Object> add(@RequestBody CustomLoginSpecialCalcAddEntity entity, InfoEntity infoEntity) throws ServiceException {
        return customLoginSpecialCalcService.add(entity);
    }

    @PostMapping("/update")
    public BaseResultDto<Object> update(@RequestBody CustomLoginSpecialCalcUpdateEntity entity, InfoEntity infoEntity) throws ServiceException {
        return customLoginSpecialCalcService.updateById(entity);
    }

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

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

    @PostMapping("/search/list")
    public BaseResultWithPagerDto<List<CustomLoginSpecialCalcDto>> searchList(@RequestBody CustomLoginSpecialCalcListEntity entity, InfoEntity infoEntity) throws ServiceException {
        return customLoginSpecialCalcService.searchList(entity);
    }
}
