package com.xiaoniu.system.platformsettings.carbrand.controller;

import com.xiaoniu.common.core.resdata.Result;
import com.xiaoniu.common.core.resdata.RowsData;
import com.xiaoniu.common.core.vo.LabelAndValueVO;
import com.xiaoniu.system.platformsettings.carbrand.dto.AddCarBrandDTO;
import com.xiaoniu.system.platformsettings.carbrand.dto.CarBrandListQueryDTO;
import com.xiaoniu.system.platformsettings.carbrand.dto.EditCarBrandDTO;
import com.xiaoniu.system.platformsettings.carbrand.service.ITbCarBrandService;
import com.xiaoniu.system.platformsettings.carbrand.vo.BrandListVO;
import com.xiaoniu.system.platformsettings.carbrand.vo.CarBrandDetailsVO;
import com.xiaoniu.system.platformsettings.carbrand.vo.CarBrandListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 车辆品牌信息表 前端控制器
 * </p>
 *
 * @author haoxuyang
 * @since 2024-10-10 05:01:01
 */
@Tag(name = "车辆信息管理")
@RestController
@RequestMapping("/carBrand")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbCarBrandController {
    private final ITbCarBrandService tbCarBrandService;

    @Operation(summary = "车辆信息列表")
    @PostMapping("/list")
    public Result<RowsData<CarBrandListVO>> list(@RequestBody CarBrandListQueryDTO dto) {
        return Result.success("查询成功", tbCarBrandService.carBrandList(dto));
    }

    @Operation(summary = "车辆信息列表（不分页、全部）")
    @GetMapping("/brandInfoList")
    public Result<List<CarBrandListVO>> brandInfoList() {
        return Result.success("查询成功", tbCarBrandService.brandInfoList());
    }

    @Operation(summary = "车辆信息列表(一级二级 下拉选)")
    @GetMapping("/brandList")
    public Result<List<BrandListVO>> brandList() {
        return Result.success("查询成功", tbCarBrandService.brandList());
    }

    @Operation(summary = "获取子车型列表")
    @PostMapping("/getCarListByParentId")
    public Result<List<CarBrandListVO>> getCarListByParentId(@RequestBody CarBrandListQueryDTO dto) {
        return Result.success("查询成功", tbCarBrandService.getCarListByParentId(dto));
    }

    @Operation(summary = "新增车辆信息")
    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated AddCarBrandDTO dto) {
        tbCarBrandService.addCarBrand(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "修改车辆信息")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody @Validated EditCarBrandDTO dto) {
        tbCarBrandService.editCarBrand(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "车辆信息详情")
    @GetMapping("/details")
    public Result<CarBrandDetailsVO> details(@Parameter(name = "id", description = "id") @RequestParam Long id) {
        return Result.success("查询成功", tbCarBrandService.details(id));
    }

    @Operation(summary = "删除车辆信息")
    @GetMapping("/del")
    public Result<String> delCarBrand(@RequestParam Long id) {
        tbCarBrandService.delCarBrand(id);
        return Result.success("操作成功");
    }

    @Operation(summary = "批量导入车辆信息")
    @PostMapping("/batchImportCarInfo")
    public Result<String> batchImportCarInfo(@RequestPart("file") MultipartFile file) throws IOException {
        tbCarBrandService.batchImportCarInfo(file);
        return Result.success("操作成功");
    }

}
