package com.cyl.h5.controller;

import com.cyl.h5.config.SecurityUtil;
import com.cyl.h5.service.H5PetService;
import com.cyl.manager.ums.domain.Pet;
import com.cyl.manager.ums.pojo.query.PetQuery;
import com.cyl.manager.ums.pojo.vo.PetVO;
import com.cyl.manager.ums.domain.Member;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.config.LocalDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宠物档案Controller
 *
 * @author daixiande
 * @date 2024-05-05
 */
//@Api("宠物档案")
@RestController
@RequestMapping("/h5/ums/pet")
public class H5PetController extends BaseController {
    @Autowired
    private H5PetService h5PetService;

    /**
     * 查询宠物档案列表
     */
    //@ApiOperation("查询宠物档案列表")
    @PostMapping("/list")
    public ResponseEntity<Page<Pet>> list( Pageable page) {
        Member member = SecurityUtil.getLocalMember();
        PetQuery  pet = new PetQuery();
        pet.setOwner(String.valueOf(member.getId()));
        List<Pet> list = h5PetService.selectList(pet, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    /**
     * 获取宠物档案详细信息
     */
    //@ApiOperation("获取宠物档案详细信息")
    @GetMapping(value = "/{id}")
    public ResponseEntity<PetVO> getInfo(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(h5PetService.selectPetById(id));
    }
    /**
     * 新增宠物档案
     */
    //@ApiOperation("新增宠物档案")
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody PetVO petVO) {
        Member member =  SecurityUtil.getLocalMember();
        petVO.setOwner(String.valueOf(member.getId()));
        return ResponseEntity.ok(h5PetService.insertPet(petVO));
    }

    /**
     * 修改宠物档案
     */
    //@ApiOperation("修改宠物档案")
    @PutMapping
    public AjaxResult edit(@RequestBody PetVO petVO) {
        Member member =  SecurityUtil.getLocalMember();
        petVO.setOwner(String.valueOf(member.getId()));
        return toAjax(h5PetService.updatePet(petVO));
    }

    /**
     * 删除宠物档案
     */
    //@ApiOperation("删除宠物档案")
	@DeleteMapping("/{ids}")
    public  ResponseEntity<Integer> remove(@PathVariable Integer[] ids) {
        return ResponseEntity.ok(h5PetService.deletePetByIds(ids));
    }
}
