package com.ningdatech.carapi.industry.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.industry.manage.RegistrationRecordManage;
import com.ningdatech.carapi.industry.model.dto.*;
import com.ningdatech.carapi.industry.model.vo.RegistrationRecordVO;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;

/**
 * <p>
 * 新车上牌记录 前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-11-06
 */
@Controller
@RequestMapping("/api/industry/registration-record")
@Slf4j
@Validated
@RestController
@Api(value = "RegistrationRecord", tags = "行业服务-新车上牌记录")
@RequiredArgsConstructor
public class RegistrationRecordController {
    private final RegistrationRecordManage registrationRecordManage;

    @ApiOperation(value = "上牌信息列表", notes = "上牌信息列表")
    @GetMapping("/info-list")
    public PageVo<RegistrationRecordVO> infoList(@Valid @ModelAttribute RegistrationRecordPageParamDTO param) {
        return registrationRecordManage.infoList(param);
    }

    @ApiOperation(value = "上牌信息详情", notes = "上牌信息详情")
    @GetMapping("/details/{id}")
    public RegistrationRecordVO details(@Valid @PathVariable Long id) {
        return registrationRecordManage.details(id);
    }

    @ApiOperation(value = "上牌信息申请列表", notes = "上牌信息申请列表")
    @GetMapping("/application-list")
    public PageVo<RegistrationRecordVO> applicationList(@Valid @ModelAttribute RegistrationRecordPageParamDTO param) {
        return registrationRecordManage.infoList(param);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public RegistrationRecordVO save(@Valid @RequestBody RegistrationRecordSaveDTO data) {
        return registrationRecordManage.save(data, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "编辑", notes = "编辑")
    @PostMapping("/modify")
    public RegistrationRecordVO modify(@Valid @RequestBody RegistrationRecordUpdateDTO data) {
        return registrationRecordManage.modify(data, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove/{id}")
    public Boolean remove(@Valid @PathVariable Long id) {
        return registrationRecordManage.remove(id, LoginUserUtil.getUserId());
    }
}
