package com.auth.service.base.controller;

import com.auth.common.model.common.result.PageResult;
import com.auth.common.model.common.result.Result;
import com.auth.common.model.common.result.ResultCodeEnum;
import com.auth.dao.base.entity.DictEntity;
import com.auth.model.base.dto.DictDto;
import com.auth.model.base.vo.DictVo;
import com.auth.service.base.service.DictService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统数据字典 前端控制器
 * </p>
 *
 * @author AuthoritySystem
 * @since 2025-07-17 23:06:38
 */
@Tag(name = "系统数据字典", description = "系统数据字典相关接口")
@RestController
@RequestMapping("/api/v1/base/dict")
@RequiredArgsConstructor
public class DictController {

    private final DictService dictService;

    @Operation(summary = "分页查询系统数据字典", description = "分页查询系统数据字典")
    @GetMapping()
    public Result<PageResult<DictVo>> getDictPage(DictDto dto) {
        Page<DictEntity> pageParams = new Page<>(dto.getPageIndex(), dto.getPageSize());
        PageResult<DictVo> pageResult = dictService.getDictPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "根据id查询系统数据字典详情", description = "根据id查询系统数据字典详情")
    @GetMapping("{id}")
    public Result<DictVo> getDictById(@PathVariable("id") Long id) {
        DictVo dictVo = dictService.getDictById(id);

        return Result.success(dictVo);
    }

    @Operation(summary = "添加系统数据字典", description = "添加系统数据字典")
    @PostMapping()
    public Result<String> addDict(@Valid @RequestBody DictDto dto) {
        dictService.addDict(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新系统数据字典", description = "更新系统数据字典")
    @PutMapping()
    public Result<String> updateDict(@Valid @RequestBody DictDto dto) {
        dictService.updateDict(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除系统数据字典", description = "删除系统数据字典")
    @DeleteMapping()
    public Result<String> deleteDict(@RequestBody List<Long> ids) {
        dictService.deleteDict(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}