package com.spring.controller;

import com.spring.domain.dto.I18nDto;
import com.spring.domain.entity.I18nEntity;
import com.spring.domain.vo.I18nVo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import com.spring.service.I18nService;
import com.spring.domain.vo.result.PageResult;
import com.spring.domain.vo.result.Result;
import com.spring.domain.vo.result.ResultCodeEnum;
import java.util.List;

/**
 * <p>
 * 多语言表 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-10 12:02:29
 */
@Tag(name = "多语言表", description = "多语言表相关接口")
@RestController
@RequestMapping("/api/product/i18n")
@RequiredArgsConstructor
public class I18nController {

    private final I18nService i18nService;

    @Operation(summary = "分页查询多语言表", description = "分页多语言表")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<I18nVo>> getI18nPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            I18nDto dto) {
        Page<I18nEntity> pageParams = new Page<>(page, limit);
        PageResult<I18nVo> pageResult = i18nService.getI18nPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加多语言表", description = "添加多语言表")
    @PostMapping()
    public Result<String> addI18n(@Valid @RequestBody I18nDto dto) {
            i18nService.addI18n(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新多语言表", description = "更新多语言表")
    @PutMapping()
    public Result<String> updateI18n(@Valid @RequestBody I18nDto dto) {
            i18nService.updateI18n(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除多语言表", description = "删除多语言表")
    @DeleteMapping()
    public Result<String> deleteI18n(@RequestBody List<Long> ids) {
            i18nService.deleteI18n(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}