package jnpf.culture.controller;

import jnpf.base.ActionResult;
import jnpf.culture.service.CulturePicSettingService;
import jnpf.model.culture.dto.CulturePicSettingDto;
import jnpf.model.culture.dto.SettingQueryDto;
import jnpf.model.culture.dto.UploadDto;
import jnpf.model.culture.vo.CulturePicSettingVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 文化打卡 - 图片配置
 *
 * @author yanwenfu
 * @create 2025-12-23
 */
@RestController
@RequestMapping(value = "/culture/pic-setting")
public class CulturePicSettingController {

    @Resource
    private CulturePicSettingService culturePicSettingService;

    /**
     * 查询图片配置数量
     * @return jnpf.base.ActionResult<java.lang.Integer>
     */
    @GetMapping(value = "/count")
    public ActionResult<Integer> getCulturePicSettingCount() {

        Integer num = culturePicSettingService.getCulturePicSettingCount();
        return ActionResult.success(num);
    }

    /**
     * 图片配置 - 列表
     * @param queryDto 查询条件
     * @return jnpf.base.ActionResult<jnpf.model.culture.vo.CulturePicSettingVo>
     */
    @GetMapping(value = "/list")
    public ActionResult<List<CulturePicSettingVo>> getPicSettingList(SettingQueryDto queryDto) {

        List<CulturePicSettingVo> list = culturePicSettingService.getPicSettingList(queryDto);
        return ActionResult.success(list);
    }

    /**
     * 图片配置 - 改名
     * @param id 图片配置id
     * @param picSettingDto 配置dto
     * @return jnpf.base.ActionResult<java.lang.Object>
     */
    @PutMapping(value = "/pic-name/{id}")
    public ActionResult<Object> updatePicName(@PathVariable(value = "id") String id, @RequestBody @Valid CulturePicSettingDto picSettingDto) {

        culturePicSettingService.updatePicName(id, picSettingDto);
        return ActionResult.success();
    }

    /**
     * 图片配置 - 批量删除
     * @param ids 图片ids(英文逗号分隔)
     * @return jnpf.base.ActionResult<java.lang.Object>
     */
    @DeleteMapping(value = "/batch")
    public ActionResult<Object> deletePicSettingBatch(@RequestParam(value = "ids") String ids) throws Exception {

        String[] split;
        try {
            split = ids.split(",");
        } catch (Exception e) {
            return ActionResult.fail("请选择要删除的图片配置");
        }
        culturePicSettingService.deletePicSettingBatch(List.of(split));
        return ActionResult.success();
    }

    /**
     * 图片配置 - 上传图片
     * @param uploadDto 上传dto
     * @return jnpf.base.ActionResult<java.lang.Object>
     */
    @PostMapping(value = "/upload")
    public ActionResult<Object> uploadPicSetting(@RequestBody @Valid UploadDto uploadDto) throws Exception {

        culturePicSettingService.uploadPicSetting(uploadDto);
        return ActionResult.success();
    }
}
