package com.crm.manager.controller;

import com.crm.manager.service.MarketExtensionService;
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.market.extension.MarketExtensionDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.market.extension.MarketExtensionAddEntity;
import com.crm.rely.backend.core.entity.market.extension.MarketExtensionDeleteEntity;
import com.crm.rely.backend.core.entity.market.extension.MarketExtensionSearchPageEntity;
import com.crm.rely.backend.core.entity.market.extension.MarketExtensionUpdateEntity;
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;

/**
 * @author: houn
 */
@RestController
@RequestMapping("/market/extension")
public class MarketExtensionController {

    @Autowired
    private MarketExtensionService marketExtensionService;

    /**
     * 添加
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated MarketExtensionAddEntity entity) throws Exception {
        marketExtensionService.add(entity);
        return  BaseResultDto.success();


    }

    /**
     * 删除
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated MarketExtensionDeleteEntity entity) throws Exception {
          marketExtensionService.delete(entity);

        return  BaseResultDto.success();
    }

    /**
     * 修改
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated MarketExtensionUpdateEntity entity) throws Exception {
          marketExtensionService.update(entity);

        return  BaseResultDto.success();
    }

    /**
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list")
    public BaseResultDto list(@RequestBody @Validated MarketExtensionSearchPageEntity entity) throws Exception {

        ResultWithPagerDto<MarketExtensionDto>
         dto= marketExtensionService.pageSearchList(entity);

        return  dto;
    }

    @PostMapping("/search/single")
    public BaseResultDto single(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        MarketExtensionDto marketExtensionDto= marketExtensionService.searchSingle(entity.getId());

        return  BaseResultDto.success(marketExtensionDto);
    }
}
