package com.crm.manager.controller;

import com.crm.manager.service.CustomGroupTypeService;
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.custom.group.type.CustomGroupTypeDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.custom.group.type.CustomGroupTypeAddEntity;
import com.crm.rely.backend.core.entity.custom.group.type.CustomGroupTypeDeleteEntity;
import com.crm.rely.backend.core.entity.custom.group.type.CustomGroupTypeSearchEntity;
import com.crm.rely.backend.core.entity.custom.group.type.CustomGroupTypeUpdateEntity;
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("/custom/group/type")
public class CustomGroupTypeController {

    @Autowired
    private CustomGroupTypeService customGroupTypeService;


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

    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated CustomGroupTypeUpdateEntity entity) throws Exception {

        customGroupTypeService.update(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated CustomGroupTypeDeleteEntity entity) throws Exception {

        customGroupTypeService.delete(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/search/list")
    public ResultWithPagerDto<CustomGroupTypeDto> searchList(@RequestBody @Validated CustomGroupTypeSearchEntity entity) throws Exception {

        return customGroupTypeService.searchPageList(entity);
    }

    @PostMapping("/search/single")
    public BaseResultDto<CustomGroupTypeDto> searchSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {

        return customGroupTypeService.searchSingle(entity);
    }


    @PostMapping("/list")
    public BaseResultDto<List<CustomGroupTypeDto>> list() throws Exception {

        return customGroupTypeService.getList();
    }


}
