package com.cyl.h5.controller.staff;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cyl.h5.config.SecurityUtil;
import com.cyl.h5.pojo.request.StaffAddressRequest;
import com.cyl.h5.service.H5MemberAddressService;
import com.cyl.manager.staff.domain.Staff;
import com.cyl.manager.staff.domain.StaffAnswerRecord;
import com.cyl.manager.staff.service.IStaffService;
import com.cyl.manager.ums.domain.Member;
import com.cyl.manager.ums.domain.MemberAddress;
import com.cyl.manager.ums.mapper.MemberAddressMapper;
import com.cyl.manager.ums.pojo.dto.MemberAddressDTO;
import com.cyl.manager.ums.pojo.query.MemberAddressQuery;
import com.cyl.manager.ums.pojo.vo.MemberAddressVO;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.config.LocalDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
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.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

//@Api("伴宠师地址")
@RestController
@RequestMapping("/h5/address/staff")
public class H5StaffAddressController {

  @Autowired
  private H5MemberAddressService h5MemberAddressService;

  @Autowired
  private MemberAddressMapper memberAddressMapper;

  @Autowired
  private IStaffService staffService;

//  @ApiOperation("伴宠师地址列表")
  @GetMapping("/list")
  public AjaxResult getList(@ApiParam(value = "当前页数", required = true, defaultValue = "1") @RequestParam Long currentPage,
                                                       @ApiParam(value = "每页数据量", required = true, defaultValue = "10") @RequestParam Long pageSize,
                                                       @ApiParam(value = "查询条件", required = false) MemberAddress address){
    Staff staff = (Staff)LocalDataUtil.getVar(Constants.STAFF_INFO);
    address.setStaffId(staff.getId());
    IPage<MemberAddress> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(currentPage, pageSize);
    IPage<MemberAddress> result =
            memberAddressMapper
                    .selectPage(page, Wrappers.query(address).lambda().orderByDesc(MemberAddress::getCreateTime));
    return AjaxResult.successData(result);
  }


//  @ApiOperation("创建伴宠师地址")
  @PostMapping("/create")
  public AjaxResult create(@RequestBody MemberAddressDTO memberAddressDTO){
    Staff staff = (Staff)LocalDataUtil.getVar(Constants.STAFF_INFO);
    memberAddressDTO.setStaffId(staff.getId());
    return AjaxResult.successData(h5MemberAddressService.insert(memberAddressDTO));
  }

//  @ApiOperation("更新伴宠师地址")
  @PutMapping("/update")
  public AjaxResult update(@RequestBody MemberAddressDTO memberAddressDTO){
    Staff staff = (Staff)LocalDataUtil.getVar(Constants.STAFF_INFO);
    memberAddressDTO.setStaffId(staff.getId());
    return AjaxResult.successData(h5MemberAddressService.update(memberAddressDTO));
  }

//  @ApiOperation("获取伴宠师地址详情")
  @GetMapping("/{id}")
  public AjaxResult getInfo(@PathVariable Long id){
    return AjaxResult.successData(h5MemberAddressService.selectById(id));
  }

//  @ApiOperation("删除伴宠师地址")
  @DeleteMapping("/{id}")
  public AjaxResult remove(@PathVariable Long id) {
    return AjaxResult.successData(h5MemberAddressService.deleteById(id));
  }
}
