package org.dromara.pet.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.pet.domain.vo.BizPetsVo;
import org.dromara.pet.domain.bo.BizPetsBo;
import org.dromara.pet.service.IBizPetsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 宠物基础档案
 *
 * @author shuo
 * @date 2026-02-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pet/pets")
public class BizPetsController extends BaseController {

    private final IBizPetsService bizPetsService;

/**
 * 查询宠物基础档案列表
 */
@SaCheckPermission("pet:pets:list")
@GetMapping("/list")
    public TableDataInfo<BizPetsVo> list(BizPetsBo bo, PageQuery pageQuery) {
        return bizPetsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出宠物基础档案列表
     */
    @SaCheckPermission("pet:pets:export")
    @Log(title = "宠物基础档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BizPetsBo bo, HttpServletResponse response) {
        List<BizPetsVo> list = bizPetsService.queryList(bo);
        ExcelUtil.exportExcel(list, "宠物基础档案", BizPetsVo.class, response);
    }

    /**
     * 获取宠物基础档案详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pet:pets:query")
    @GetMapping("/{id}")
    public R<BizPetsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(bizPetsService.queryById(id));
    }

    /**
     * 新增宠物基础档案
     */
    @SaCheckPermission("pet:pets:add")
    @Log(title = "宠物基础档案", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BizPetsBo bo) {
        return toAjax(bizPetsService.insertByBo(bo));
    }

    /**
     * 修改宠物基础档案
     */
    @SaCheckPermission("pet:pets:edit")
    @Log(title = "宠物基础档案", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BizPetsBo bo) {
        return toAjax(bizPetsService.updateByBo(bo));
    }

    /**
     * 删除宠物基础档案
     *
     * @param ids 主键串
     */
    @SaCheckPermission("pet:pets:remove")
    @Log(title = "宠物基础档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(bizPetsService.deleteWithValidByIds(List.of(ids), true));
    }
}
