package com.crm.activity.controller.custom;

import com.crm.activity.service.ActivityRaceSignService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.model.dto.activity.ActivityRaceSignInfoDto;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignAddEntity;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignInfoEntity;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignListEntity;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignLoginEntity;
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;

/**
 * 比赛报名api
 *
 * @author y
 * @create 2022/7/19
 */
@RestController
@RequestMapping("/custom/service/activity/race/sign")
public class ActivityRaceSignCsController {

    @Autowired
    private ActivityRaceSignService activityRaceSignService;

    /**
     * 添加报名
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto<Boolean> add(@RequestBody ActivityRaceSignAddEntity entity) throws Exception {
        activityRaceSignService.add(entity);
        return BaseResultDto.success(true);
    }

    /**
     * 最近一次报名信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/recent")
    public BaseResultDto<ActivityRaceSignInfoDto> info(@RequestBody ActivityRaceSignInfoEntity entity) throws Exception {
        return BaseResultDto.success(activityRaceSignService.info(entity));
    }

    /**
     * 根据ID获取报名信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/single")
    public BaseResultDto<ActivityRaceSignInfoDto> searchSingle(@RequestBody SingleLongEntity entity) throws Exception {
        return BaseResultDto.success(activityRaceSignService.searchById(entity.getId()));
    }

    /**
     * 报名列表
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list")
    public BaseResultWithPagerDto<List<ActivityRaceSignInfoDto>> searchList(@RequestBody ActivityRaceSignListEntity entity) throws Exception {
        return activityRaceSignService.searchList(entity);
    }

    @PostMapping("/logins")
    public BaseResultDto<List<Long>> logins(@RequestBody ActivityRaceSignLoginEntity entity) throws Exception {
        return BaseResultDto.success(activityRaceSignService.getLogins(entity));
    }
}
