package org.springblade.estate.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.estate.dto.AuthorizeRecordsDTO;
import org.springblade.estate.dto.UserAccessPermissionsDTO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.estate.entity.UserAccessPermissions;
import org.springblade.estate.vo.UserAccessPermissionsVO;
import org.springblade.estate.wrapper.UserAccessPermissionsWrapper;
import org.springblade.estate.service.IUserAccessPermissionsService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2022-01-07
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/useraccesspermissions")

public class UserAccessPermissionsClient implements IUserAccessPermissionsClient {

    private final IUserAccessPermissionsService userAccessPermissionsService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public UserAccessPermissionsVO detail(UserAccessPermissions userAccessPermissions) {
        UserAccessPermissions detail = userAccessPermissionsService.getOne(Condition.getQueryWrapper(userAccessPermissions));
        return UserAccessPermissionsWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<UserAccessPermissionsVO> list(UserAccessPermissions userAccessPermissions) {
        return UserAccessPermissionsWrapper.build().listVO(userAccessPermissionsService.list(Condition.getQueryWrapper(userAccessPermissions)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody UserAccessPermissions userAccessPermissions) {
        return userAccessPermissionsService.save(userAccessPermissions);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody UserAccessPermissions userAccessPermissions) {
        return userAccessPermissionsService.updateById(userAccessPermissions);
        }

    /**
     * 新增或修改
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody UserAccessPermissions userAccessPermissions) {
        return userAccessPermissionsService.saveOrUpdate(userAccessPermissions);
        }


    /**
     * 删除
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return userAccessPermissionsService.deleteLogic(Func.toLongList(ids));
        }

	@Override
	@PostMapping("/generateUserAccessPermissions")
	public R generateUserAccessPermissions(@RequestBody AuthorizeRecordsDTO authorizeRecordsDTO) {
		return this.userAccessPermissionsService.generateUserAccessPermissions(authorizeRecordsDTO);
	}

	@Override
	@PostMapping("/deleteUserAccessPermissions")
	public R deleteUserAccessPermissions(@RequestBody AuthorizeRecordsDTO authorizeRecordsDTO) {
		return this.userAccessPermissionsService.deleteUserAccessPermissions(authorizeRecordsDTO);
	}

	/**
	 * 获取已下发的id列表
	 */
	@Override
	@GetMapping("/getUserIdsByUserType")
	public List<Long> getUserIdsByUserType(@RequestParam String userType) {
		return userAccessPermissionsService.getUserIdsByUserType(userType);
	}

	@Override
	@PostMapping("/pushFace")
	public R pushFace(@RequestBody UserAccessPermissionsDTO userAccessPermissionsDTO) {
		return userAccessPermissionsService.pushFace(userAccessPermissionsDTO);
	}

	@Override
	@PostMapping("/deleteFace")
	public R deleteFace(@RequestParam(value = "userId") String userId, @RequestParam(value = "userType") String userType) {
		return userAccessPermissionsService.deleteFace(userId, userType);
	}

	@Override
	@PostMapping("/getListByUserAndAddress")
	public List<UserAccessPermissionsVO> getListByUserAndAddress(@RequestParam(value = "userId") String userId, @RequestParam(value = "userType") String userType,
													   @RequestParam(value = "residentialId", required =  false) Long residentialId, @RequestParam(value = "unitId", required =  false) Long unitId,
																 @RequestParam(value = "permissions") Integer permissions) {
		return userAccessPermissionsService.getListByUserAndAddress(userId, userType, residentialId, unitId, permissions);
	}


}
