package com.sundot.airport.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.annotation.Anonymous;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.system.domain.BaseDefaultChoise;
import com.sundot.airport.system.service.IBaseDefaultChoiseService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;

/**
 * 默认选择配置Controller
 *
 * @author ruoyi
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/system/defaultChoise")
public class BaseDefaultChoiseController extends BaseController {
    @Autowired
    private IBaseDefaultChoiseService baseDefaultChoiseService;

    /**
     * 查询默认选择配置列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(BaseDefaultChoise baseDefaultChoise) {
        startPage();
        List<BaseDefaultChoise> list = baseDefaultChoiseService.selectBaseDefaultChoiseList(baseDefaultChoise);
        return getDataTable(list);
    }

    /**
     * 导出默认选择配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:defaultChoise:export')")
    @Log(title = "默认选择配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseDefaultChoise baseDefaultChoise) {
        List<BaseDefaultChoise> list = baseDefaultChoiseService.selectBaseDefaultChoiseList(baseDefaultChoise);
        ExcelUtil<BaseDefaultChoise> util = new ExcelUtil<BaseDefaultChoise>(BaseDefaultChoise.class);
        util.exportExcel(response, list, "默认选择配置数据");
    }

    /**
     * 获取默认选择配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:defaultChoise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(baseDefaultChoiseService.selectBaseDefaultChoiseById(id));
    }

    /**
     * 新增默认选择配置
     */
    @PreAuthorize("@ss.hasPermi('system:defaultChoise:add')")
    @Log(title = "默认选择配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseDefaultChoise baseDefaultChoise) {
        return toAjax(baseDefaultChoiseService.insertBaseDefaultChoise(baseDefaultChoise));
    }

    /**
     * 修改默认选择配置
     */
    @PreAuthorize("@ss.hasPermi('system:defaultChoise:edit')")
    @Log(title = "默认选择配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseDefaultChoise baseDefaultChoise) {
        return toAjax(baseDefaultChoiseService.updateBaseDefaultChoise(baseDefaultChoise));
    }

    /**
     * 删除默认选择配置
     */
    @PreAuthorize("@ss.hasPermi('system:defaultChoise:remove')")
    @Log(title = "默认选择配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseDefaultChoiseService.deleteBaseDefaultChoiseByIds(ids));
    }

    /**
     * 获取默认选择的分类信息（包含ID、名称及父类信息）
     */
    @Anonymous
    @GetMapping("/categoryInfo/{categoryType}")
    public AjaxResult getCategoryInfo(@PathVariable("categoryType") Integer categoryType) {
        List<BaseDefaultChoise> list = baseDefaultChoiseService.selectDefaultCategoryWithInfo(categoryType);
        return success(list);
    }
}